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 <gdk/gdk.h> | 7 #include <gdk/gdk.h> |
8 #include <gdk/gdkx.h> | 8 #include <gdk/gdkx.h> |
9 #include <gtk/gtk.h> | 9 #include <gtk/gtk.h> |
10 #include <stddef.h> | 10 #include <stddef.h> |
11 | 11 |
12 #include <memory> | 12 #include <memory> |
13 | 13 |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/debug/leak_annotations.h" | 15 #include "base/debug/leak_annotations.h" |
16 #include "base/environment.h" | 16 #include "base/environment.h" |
17 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
18 #include "ui/aura/window_tree_host.h" | 18 #include "ui/aura/window_tree_host.h" |
19 #include "ui/base/accelerators/accelerator.h" | 19 #include "ui/base/accelerators/accelerator.h" |
20 #include "ui/events/event_constants.h" | 20 #include "ui/events/event_constants.h" |
21 #include "ui/events/keycodes/keyboard_code_conversion_x.h" | 21 #include "ui/events/keycodes/keyboard_code_conversion_x.h" |
| 22 #include "ui/gfx/color_utils.h" |
22 #include "ui/gfx/geometry/size.h" | 23 #include "ui/gfx/geometry/size.h" |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 const char kAuraTransientParent[] = "aura-transient-parent"; | 27 const char kAuraTransientParent[] = "aura-transient-parent"; |
27 | 28 |
28 void CommonInitFromCommandLine(const base::CommandLine& command_line, | 29 void CommonInitFromCommandLine(const base::CommandLine& command_line, |
29 void (*init_func)(gint*, gchar***)) { | 30 void (*init_func)(gint*, gchar***)) { |
30 const std::vector<std::string>& args = command_line.argv(); | 31 const std::vector<std::string>& args = command_line.argv(); |
31 int argc = args.size(); | 32 int argc = args.size(); |
(...skipping 13 matching lines...) Expand all Loading... |
45 } | 46 } |
46 for (size_t i = 0; i < args.size(); ++i) { | 47 for (size_t i = 0; i < args.size(); ++i) { |
47 free(argv[i]); | 48 free(argv[i]); |
48 } | 49 } |
49 } | 50 } |
50 | 51 |
51 } // namespace | 52 } // namespace |
52 | 53 |
53 namespace libgtkui { | 54 namespace libgtkui { |
54 | 55 |
| 56 // Theme colors returned by GetSystemColor(). |
| 57 const SkColor kInvalidColorIdColor = SkColorSetRGB(255, 0, 128); |
| 58 const SkColor kURLTextColor = SkColorSetRGB(0x0b, 0x80, 0x43); |
| 59 |
| 60 SkColor NormalURLColor(SkColor foreground) { |
| 61 color_utils::HSL fg_hsl, hue_hsl; |
| 62 color_utils::SkColorToHSL(foreground, &fg_hsl); |
| 63 color_utils::SkColorToHSL(kURLTextColor, &hue_hsl); |
| 64 |
| 65 // Only allow colors that have a fair amount of saturation in them (color vs |
| 66 // white). This means that our output color will always be fairly green. |
| 67 double s = std::max(0.5, fg_hsl.s); |
| 68 |
| 69 // Make sure the luminance is at least as bright as the |kURLTextColor| green |
| 70 // would be if we were to use that. |
| 71 double l; |
| 72 if (fg_hsl.l < hue_hsl.l) |
| 73 l = hue_hsl.l; |
| 74 else |
| 75 l = (fg_hsl.l + hue_hsl.l) / 2; |
| 76 |
| 77 color_utils::HSL output = {hue_hsl.h, s, l}; |
| 78 return color_utils::HSLToSkColor(output, 255); |
| 79 } |
| 80 |
| 81 SkColor SelectedURLColor(SkColor foreground, SkColor background) { |
| 82 color_utils::HSL fg_hsl, bg_hsl, hue_hsl; |
| 83 color_utils::SkColorToHSL(foreground, &fg_hsl); |
| 84 color_utils::SkColorToHSL(background, &bg_hsl); |
| 85 color_utils::SkColorToHSL(kURLTextColor, &hue_hsl); |
| 86 |
| 87 // The saturation of the text should be opposite of the background, clamped |
| 88 // to 0.2-0.8. We make sure it's greater than 0.2 so there's some color, but |
| 89 // less than 0.8 so it's not the oversaturated neon-color. |
| 90 double opposite_s = 1 - bg_hsl.s; |
| 91 double s = std::max(0.2, std::min(0.8, opposite_s)); |
| 92 |
| 93 // The luminance should match the luminance of the foreground text. Again, |
| 94 // we clamp so as to have at some amount of color (green) in the text. |
| 95 double opposite_l = fg_hsl.l; |
| 96 double l = std::max(0.1, std::min(0.9, opposite_l)); |
| 97 |
| 98 color_utils::HSL output = {hue_hsl.h, s, l}; |
| 99 return color_utils::HSLToSkColor(output, 255); |
| 100 } |
| 101 |
55 void GtkInitFromCommandLine(const base::CommandLine& command_line) { | 102 void GtkInitFromCommandLine(const base::CommandLine& command_line) { |
56 CommonInitFromCommandLine(command_line, gtk_init); | 103 CommonInitFromCommandLine(command_line, gtk_init); |
57 } | 104 } |
58 | 105 |
59 // TODO(erg): This method was copied out of shell_integration_linux.cc. Because | 106 // TODO(erg): This method was copied out of shell_integration_linux.cc. Because |
60 // of how this library is structured as a stand alone .so, we can't call code | 107 // of how this library is structured as a stand alone .so, we can't call code |
61 // from browser and above. | 108 // from browser and above. |
62 std::string GetDesktopName(base::Environment* env) { | 109 std::string GetDesktopName(base::Environment* env) { |
63 #if defined(GOOGLE_CHROME_BUILD) | 110 #if defined(GOOGLE_CHROME_BUILD) |
64 return "google-chrome.desktop"; | 111 return "google-chrome.desktop"; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 aura::Window* GetAuraTransientParent(GtkWidget* dialog) { | 182 aura::Window* GetAuraTransientParent(GtkWidget* dialog) { |
136 return reinterpret_cast<aura::Window*>( | 183 return reinterpret_cast<aura::Window*>( |
137 g_object_get_data(G_OBJECT(dialog), kAuraTransientParent)); | 184 g_object_get_data(G_OBJECT(dialog), kAuraTransientParent)); |
138 } | 185 } |
139 | 186 |
140 void ClearAuraTransientParent(GtkWidget* dialog) { | 187 void ClearAuraTransientParent(GtkWidget* dialog) { |
141 g_object_set_data(G_OBJECT(dialog), kAuraTransientParent, NULL); | 188 g_object_set_data(G_OBJECT(dialog), kAuraTransientParent, NULL); |
142 } | 189 } |
143 | 190 |
144 } // namespace libgtkui | 191 } // namespace libgtkui |
OLD | NEW |