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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 // Get the color value of the single pixel. | 398 // Get the color value of the single pixel. |
393 SkColor GetPixelValue() { | 399 SkColor GetPixelValue() { |
394 return *reinterpret_cast<SkColor*>(cairo_image_surface_get_data(surface_)); | 400 return *reinterpret_cast<SkColor*>(cairo_image_surface_get_data(surface_)); |
395 } | 401 } |
396 | 402 |
397 private: | 403 private: |
398 cairo_surface_t* surface_; | 404 cairo_surface_t* surface_; |
399 cairo_t* cairo_; | 405 cairo_t* cairo_; |
400 }; | 406 }; |
401 | 407 |
402 void RenderBackground(cairo_t* cr, GtkStyleContext* context) { | 408 void RenderBackground(const gfx::Size& size, |
| 409 cairo_t* cr, |
| 410 GtkStyleContext* context) { |
403 if (!context) | 411 if (!context) |
404 return; | 412 return; |
405 RenderBackground(cr, gtk_style_context_get_parent(context)); | 413 RenderBackground(size, cr, gtk_style_context_get_parent(context)); |
406 gtk_render_background(context, cr, 0, 0, 1, 1); | 414 gtk_render_background(context, cr, 0, 0, size.width(), size.height()); |
407 } | 415 } |
408 | 416 |
409 SkColor GetBgColor(const char* css_selector) { | 417 SkColor GetBgColor(const char* css_selector) { |
410 // Backgrounds are more general than solid colors (eg. gradients), | 418 // Backgrounds are more general than solid colors (eg. gradients), |
411 // but chromium requires us to boil this down to one color. We | 419 // but chromium requires us to boil this down to one color. We |
412 // cannot use the background-color here because some themes leave it | 420 // cannot use the background-color here because some themes leave it |
413 // set to a garbage color because a background-image will cover it | 421 // set to a garbage color because a background-image will cover it |
414 // anyway. So we instead render the background into a single pixel, | 422 // anyway. So we instead render the background into a single pixel, |
415 // removing any borders, and hope that we get a good color. | 423 // removing any borders, and hope that we get a good color. |
416 auto context = GetStyleContextFromCss(css_selector); | 424 auto context = GetStyleContextFromCss(css_selector); |
417 RemoveBorders(context); | 425 RemoveBorders(context); |
418 PixelSurface surface; | 426 PixelSurface surface; |
419 RenderBackground(surface.cairo(), context); | 427 RenderBackground(gfx::Size(1, 1), surface.cairo(), context); |
420 return surface.GetPixelValue(); | 428 return surface.GetPixelValue(); |
421 } | 429 } |
422 | 430 |
423 SkColor GetBorderColor(const char* css_selector) { | 431 SkColor GetBorderColor(const char* css_selector) { |
424 // Borders have the same issue as backgrounds, due to the | 432 // Borders have the same issue as backgrounds, due to the |
425 // border-image property. | 433 // border-image property. |
426 auto context = GetStyleContextFromCss(css_selector); | 434 auto context = GetStyleContextFromCss(css_selector); |
427 GtkStateFlags state = gtk_style_context_get_state(context); | 435 GtkStateFlags state = gtk_style_context_get_state(context); |
428 GtkBorderStyle border_style = GTK_BORDER_STYLE_NONE; | 436 GtkBorderStyle border_style = GTK_BORDER_STYLE_NONE; |
429 gtk_style_context_get(context, state, GTK_STYLE_PROPERTY_BORDER_STYLE, | 437 gtk_style_context_get(context, state, GTK_STYLE_PROPERTY_BORDER_STYLE, |
430 &border_style, nullptr); | 438 &border_style, nullptr); |
431 GtkBorder border; | 439 GtkBorder border; |
432 gtk_style_context_get_border(context, state, &border); | 440 gtk_style_context_get_border(context, state, &border); |
433 if ((border_style == GTK_BORDER_STYLE_NONE || | 441 if ((border_style == GTK_BORDER_STYLE_NONE || |
434 border_style == GTK_BORDER_STYLE_HIDDEN) || | 442 border_style == GTK_BORDER_STYLE_HIDDEN) || |
435 (!border.left && !border.right && !border.top && !border.bottom)) { | 443 (!border.left && !border.right && !border.top && !border.bottom)) { |
436 return SK_ColorTRANSPARENT; | 444 return SK_ColorTRANSPARENT; |
437 } | 445 } |
438 | 446 |
439 AddBorders(context); | 447 AddBorders(context); |
440 PixelSurface surface; | 448 PixelSurface surface; |
441 RenderBackground(surface.cairo(), context); | 449 RenderBackground(gfx::Size(1, 1), surface.cairo(), context); |
442 gtk_render_frame(context, surface.cairo(), 0, 0, 1, 1); | 450 gtk_render_frame(context, surface.cairo(), 0, 0, 1, 1); |
443 return surface.GetPixelValue(); | 451 return surface.GetPixelValue(); |
444 } | 452 } |
445 #endif | 453 #endif |
446 | 454 |
447 } // namespace libgtkui | 455 } // namespace libgtkui |
OLD | NEW |