thomasanderson | acc4214 | 2017-01-10 21:11:45 | [diff] [blame] | 1 | # Linux GTK Theme Integration |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 2 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 3 | The GTK+ port of Chromium has a mode where we try to match the user's GTK theme |
thomasanderson | acc4214 | 2017-01-10 21:11:45 | [diff] [blame] | 4 | (which can be enabled under Settings -> Appearance -> Use GTK+ theme). |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 5 | |
thomasanderson | acc4214 | 2017-01-10 21:11:45 | [diff] [blame] | 6 | ## How Chromium determines which colors to use |
| 7 | |
| 8 | GTK3 added a new CSS theming engine which gives fine-tuned control over how |
| 9 | widgets are styled. Chromium's themes, by contrast, are much simpler: it is |
| 10 | mostly a list of about 80 colors (see //src/ui/native_theme/native_theme.h) |
| 11 | overridden by the theme. Chromium usually doesn't use GTK to render entire |
| 12 | widgets, but instead tries to determine colors from them. |
| 13 | |
thomasanderson | 419a91a1 | 2017-02-10 20:05:48 | [diff] [blame] | 14 | Chromium needs foreground, background and border colors from widgets. The |
| 15 | foreground color is simply taken from the CSS "color" property. Backgrounds and |
| 16 | borders are complicated because in general they might have multiple gradients or |
| 17 | images. To get the color, Chromium uses GTK to render the background or border |
| 18 | into a 24x24 bitmap and uses the average color for theming. This mostly gives |
| 19 | reasonable results, but in case theme authors do not like the resulting color, |
| 20 | they have the option to theme Chromium widgets specially. |
thomasanderson | acc4214 | 2017-01-10 21:11:45 | [diff] [blame] | 21 | |
| 22 | ## Note to GTK theme authors: How to theme Chromium widgets |
| 23 | |
| 24 | Every widget Chromium uses will have a "chromium" style class added to it. For |
thomasanderson | 419a91a1 | 2017-02-10 20:05:48 | [diff] [blame] | 25 | example, a textfield selector might look like: |
thomasanderson | acc4214 | 2017-01-10 21:11:45 | [diff] [blame] | 26 | |
| 27 | ``` |
| 28 | .window.background.chromium .entry.chromium |
| 29 | ``` |
| 30 | |
| 31 | If themes want to handle Chromium textfields specially, for GTK3.0 - GTK3.19, |
| 32 | they might use: |
| 33 | |
| 34 | ``` |
| 35 | /* Normal case */ |
| 36 | .entry { |
| 37 | color: #ffffff; |
| 38 | background-color: #000000; |
| 39 | } |
| 40 | |
| 41 | /* Chromium-specific case */ |
| 42 | .entry.chromium { |
| 43 | color: #ff0000; |
| 44 | background-color: #00ff00; |
| 45 | } |
| 46 | ``` |
| 47 | |
| 48 | For GTK3.20 or later, themes will as usual have to replace ".entry" with |
| 49 | "entry". |
| 50 | |
thomasanderson | acc4214 | 2017-01-10 21:11:45 | [diff] [blame] | 51 | The list of CSS selectors that Chromium uses to determine its colors is in |
Tom Anderson | 61fbaaf | 2020-04-02 23:16:23 | [diff] [blame] | 52 | //src/ui/gtk/native_theme_gtk.cc. |