| 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_ui.h" | 5 #include "chrome/browser/ui/libgtkui/gtk_ui.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <pango/pango.h> | 8 #include <pango/pango.h> |
| 9 #include <X11/Xcursor/Xcursor.h> | 9 #include <X11/Xcursor/Xcursor.h> |
| 10 | 10 |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 | 221 |
| 222 // Prefix for app indicator ids | 222 // Prefix for app indicator ids |
| 223 const char kAppIndicatorIdPrefix[] = "chrome_app_indicator_"; | 223 const char kAppIndicatorIdPrefix[] = "chrome_app_indicator_"; |
| 224 | 224 |
| 225 // Number of app indicators used (used as part of app-indicator id). | 225 // Number of app indicators used (used as part of app-indicator id). |
| 226 int indicators_count; | 226 int indicators_count; |
| 227 | 227 |
| 228 // The unknown content type. | 228 // The unknown content type. |
| 229 const char* kUnknownContentType = "application/octet-stream"; | 229 const char* kUnknownContentType = "application/octet-stream"; |
| 230 | 230 |
| 231 // Picks a button tint from a set of background colors. While | |
| 232 // |accent_color| will usually be the same color through a theme, this | |
| 233 // function will get called with the normal GtkLabel |text_color|/GtkWindow | |
| 234 // |background_color| pair and the GtkEntry |text_color|/|background_color| | |
| 235 // pair. While 3/4 of the time the resulting tint will be the same, themes that | |
| 236 // have a dark window background (with light text) and a light text entry (with | |
| 237 // dark text) will get better icons with this separated out. | |
| 238 void PickButtonTintFromColors(SkColor accent_color, | |
| 239 SkColor text_color, | |
| 240 SkColor background_color, | |
| 241 color_utils::HSL* tint) { | |
| 242 color_utils::HSL accent_tint, text_tint, background_tint; | |
| 243 color_utils::SkColorToHSL(accent_color, &accent_tint); | |
| 244 color_utils::SkColorToHSL(text_color, &text_tint); | |
| 245 color_utils::SkColorToHSL(background_color, &background_tint); | |
| 246 | |
| 247 // If the accent color is gray, then our normal HSL tomfoolery will bring out | |
| 248 // whatever color is oddly dominant (for example, in rgb space [125, 128, | |
| 249 // 125] will tint green instead of gray). Slight differences (+/-10 (4%) to | |
| 250 // all color components) should be interpreted as this color being gray and | |
| 251 // we should switch into a special grayscale mode. | |
| 252 int rb_diff = abs(static_cast<int>(SkColorGetR(accent_color)) - | |
| 253 static_cast<int>(SkColorGetB(accent_color))); | |
| 254 int rg_diff = abs(static_cast<int>(SkColorGetR(accent_color)) - | |
| 255 static_cast<int>(SkColorGetG(accent_color))); | |
| 256 int bg_diff = abs(static_cast<int>(SkColorGetB(accent_color)) - | |
| 257 static_cast<int>(SkColorGetG(accent_color))); | |
| 258 if (rb_diff < 10 && rg_diff < 10 && bg_diff < 10) { | |
| 259 // Our accent is white/gray/black. Only the luminance of the accent color | |
| 260 // matters. | |
| 261 tint->h = -1; | |
| 262 | |
| 263 // Use the saturation of the text. | |
| 264 tint->s = text_tint.s; | |
| 265 | |
| 266 // Use the luminance of the accent color UNLESS there isn't enough | |
| 267 // luminance contrast between the accent color and the base color. | |
| 268 if (fabs(accent_tint.l - background_tint.l) > 0.3) | |
| 269 tint->l = accent_tint.l; | |
| 270 else | |
| 271 tint->l = text_tint.l; | |
| 272 } else { | |
| 273 // Our accent is a color. | |
| 274 tint->h = accent_tint.h; | |
| 275 | |
| 276 // Don't modify the saturation; the amount of color doesn't matter. | |
| 277 tint->s = -1; | |
| 278 | |
| 279 // If the text wants us to darken the icon, don't change the luminance (the | |
| 280 // icons are already dark enough). Otherwise, lighten the icon by no more | |
| 281 // than 0.9 since we don't want a pure-white icon even if the text is pure | |
| 282 // white. | |
| 283 if (text_tint.l < 0.5) | |
| 284 tint->l = -1; | |
| 285 else if (text_tint.l <= 0.9) | |
| 286 tint->l = text_tint.l; | |
| 287 else | |
| 288 tint->l = 0.9; | |
| 289 } | |
| 290 } | |
| 291 | |
| 292 // Returns a gfx::FontRenderParams corresponding to GTK's configuration. | 231 // Returns a gfx::FontRenderParams corresponding to GTK's configuration. |
| 293 gfx::FontRenderParams GetGtkFontRenderParams() { | 232 gfx::FontRenderParams GetGtkFontRenderParams() { |
| 294 GtkSettings* gtk_settings = gtk_settings_get_default(); | 233 GtkSettings* gtk_settings = gtk_settings_get_default(); |
| 295 CHECK(gtk_settings); | 234 CHECK(gtk_settings); |
| 296 gint antialias = 0; | 235 gint antialias = 0; |
| 297 gint hinting = 0; | 236 gint hinting = 0; |
| 298 gchar* hint_style = nullptr; | 237 gchar* hint_style = nullptr; |
| 299 gchar* rgba = nullptr; | 238 gchar* rgba = nullptr; |
| 300 g_object_get(gtk_settings, "gtk-xft-antialias", &antialias, "gtk-xft-hinting", | 239 g_object_get(gtk_settings, "gtk-xft-antialias", &antialias, "gtk-xft-hinting", |
| 301 &hinting, "gtk-xft-hintstyle", &hint_style, "gtk-xft-rgba", | 240 &hinting, "gtk-xft-hintstyle", &hint_style, "gtk-xft-rgba", |
| (...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1073 | 1012 |
| 1074 float GtkUi::GetDeviceScaleFactor() const { | 1013 float GtkUi::GetDeviceScaleFactor() const { |
| 1075 return device_scale_factor_; | 1014 return device_scale_factor_; |
| 1076 } | 1015 } |
| 1077 | 1016 |
| 1078 } // namespace libgtkui | 1017 } // namespace libgtkui |
| 1079 | 1018 |
| 1080 views::LinuxUI* BuildGtkUi() { | 1019 views::LinuxUI* BuildGtkUi() { |
| 1081 return new libgtkui::GtkUi; | 1020 return new libgtkui::GtkUi; |
| 1082 } | 1021 } |
| OLD | NEW |