OLD | NEW |
1 Linux GTK Theme Integration | 1 # Linux GTK Theme Integration |
2 | 2 |
3 The GTK+ port of Chromium has a mode where we try to match the user's GTK theme | 3 The GTK+ port of Chromium has a mode where we try to match the user's GTK theme |
4 (which can be enabled under Wrench -> Options -> Personal Stuff -> Set to GTK+ | 4 (which can be enabled under Settings -> Appearance -> Use GTK+ theme). |
5 theme). The heuristics often don't pick good colors due to a lack of information | |
6 in the GTK themes. | |
7 | 5 |
8 Starting in Chrome 9, we're providing a new way for theme authors to control our | 6 # GTK3 |
9 GTK+ theming mode. I am not sure of the earliest build these showed up in, but I | 7 |
10 know 9.0.597 works. | 8 At some point after version 57, Chromium will switch to using the GTK3 theme by |
| 9 default. |
| 10 |
| 11 ## How Chromium determines which colors to use |
| 12 |
| 13 GTK3 added a new CSS theming engine which gives fine-tuned control over how |
| 14 widgets are styled. Chromium's themes, by contrast, are much simpler: it is |
| 15 mostly a list of about 80 colors (see //src/ui/native_theme/native_theme.h) |
| 16 overridden by the theme. Chromium usually doesn't use GTK to render entire |
| 17 widgets, but instead tries to determine colors from them. |
| 18 |
| 19 There are three types of colors Chromium needs from widgets: |
| 20 |
| 21 * Foreground color: determined by the CSS "color" property |
| 22 * Background color: determined by the CSS "background-color" and "background-ima
ge" properties |
| 23 * Border color: determined by the "border-color", "border-image", |
| 24 "border-style", and "border-width" properties |
| 25 |
| 26 Backgrounds and borders are complicated because in general they might have |
| 27 multiple gradients or images. To get the color, Chromium uses GTK to render the |
| 28 background or border into a single pixel and uses the resulting color for |
| 29 theming. This mostly gives reasonable results, but in case theme authors do not |
| 30 like the resulting color, they have the option to theme Chromium widgets |
| 31 specially. |
| 32 |
| 33 ## Note to GTK theme authors: How to theme Chromium widgets |
| 34 |
| 35 Every widget Chromium uses will have a "chromium" style class added to it. For |
| 36 example, a texfield selector might look like: |
| 37 |
| 38 ``` |
| 39 .window.background.chromium .entry.chromium |
| 40 ``` |
| 41 |
| 42 If themes want to handle Chromium textfields specially, for GTK3.0 - GTK3.19, |
| 43 they might use: |
| 44 |
| 45 ``` |
| 46 /* Normal case */ |
| 47 .entry { |
| 48 color: #ffffff; |
| 49 background-color: #000000; |
| 50 } |
| 51 |
| 52 /* Chromium-specific case */ |
| 53 .entry.chromium { |
| 54 color: #ff0000; |
| 55 background-color: #00ff00; |
| 56 } |
| 57 ``` |
| 58 |
| 59 For GTK3.20 or later, themes will as usual have to replace ".entry" with |
| 60 "entry". |
| 61 |
| 62 Additional requirements for border colors to be picked up: |
| 63 |
| 64 * Must have a border-style that is not none. |
| 65 * Must have a border-width that is nonzero. |
| 66 |
| 67 The list of CSS selectors that Chromium uses to determine its colors is in |
| 68 //src/chrome/browser/ui/libgtkui/native_theme_gtk3.cc. |
| 69 |
| 70 # GTK2 |
| 71 |
| 72 Chromium's GTK2 theme will soon be deprecated, and this section will be removed. |
11 | 73 |
12 ## Describing the previous heuristics | 74 ## Describing the previous heuristics |
13 | 75 |
14 The frame heuristics were simple. Query the `bg[SELECTED]` and `bg[INSENSITIVE]` | 76 The heuristics often don't pick good colors due to a lack of information in the |
15 colors on the `MetaFrames` class and darken them slightly. This usually worked | 77 GTK themes. The frame heuristics were simple. Query the `bg[SELECTED]` and |
16 OK until the rise of themes that try to make a unified titlebar/menubar look. At | 78 `bg[INSENSITIVE]` colors on the `MetaFrames` class and darken them |
17 roughly that time, it seems that people stopped specifying color information for | 79 slightly. This usually worked OK until the rise of themes that try to make a |
18 the `MetaFrames` class and this has lead to the very orange chrome frame on | 80 unified titlebar/menubar look. At roughly that time, it seems that people |
19 Maverick. | 81 stopped specifying color information for the `MetaFrames` class and this has |
| 82 lead to the very orange chrome frame on Maverick. |
20 | 83 |
21 `MetaFrames` is (was?) a class that was used to communicate frame color data to | 84 `MetaFrames` is (was?) a class that was used to communicate frame color data to |
22 the window manager around the Hardy days. (It's still defined in most of | 85 the window manager around the Hardy days. (It's still defined in most of |
23 [XFCE's themes](http://packages.ubuntu.com/maverick/gtk2-engines-xfce)). In | 86 [XFCE's themes](http://packages.ubuntu.com/maverick/gtk2-engines-xfce)). In |
24 chrome's implementation, `MetaFrames` derives from `GtkWindow`. | 87 chrome's implementation, `MetaFrames` derives from `GtkWindow`. |
25 | 88 |
26 If you are happy with the defaults that chrome has picked, no action is | 89 If you are happy with the defaults that chrome has picked, no action is |
27 necessary on the part of the theme author. | 90 necessary on the part of the theme author. |
28 | 91 |
29 ## Introducing `ChromeGtkFrame` | 92 ## Introducing `ChromeGtkFrame` |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 | 189 |
127 `MetaFrames` is a class that was used in metacity to communicate color | 190 `MetaFrames` is a class that was used in metacity to communicate color |
128 information to the window manager. During the Hardy Heron days, we slurped up | 191 information to the window manager. During the Hardy Heron days, we slurped up |
129 the data and used it as a key part of our heuristics. At least on my Lucid Lynx | 192 the data and used it as a key part of our heuristics. At least on my Lucid Lynx |
130 machine, none of the GNOME GTK+ themes have `MetaFrames` styling. (As mentioned | 193 machine, none of the GNOME GTK+ themes have `MetaFrames` styling. (As mentioned |
131 above, several of the XFCE themes do, though.) | 194 above, several of the XFCE themes do, though.) |
132 | 195 |
133 Internally to chrome, our `ChromeGtkFrame` class inherits from `MetaFrames` | 196 Internally to chrome, our `ChromeGtkFrame` class inherits from `MetaFrames` |
134 (again, which inherits from `GtkWindow`) so any old themes that style the | 197 (again, which inherits from `GtkWindow`) so any old themes that style the |
135 `MetaFrames` class are backwards compatible. | 198 `MetaFrames` class are backwards compatible. |
OLD | NEW |