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/gtk2_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 #include <set> | 10 #include <set> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/debug/leak_annotations.h" | 14 #include "base/debug/leak_annotations.h" |
15 #include "base/environment.h" | 15 #include "base/environment.h" |
16 #include "base/i18n/rtl.h" | 16 #include "base/i18n/rtl.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
19 #include "base/nix/mime_util_xdg.h" | 19 #include "base/nix/mime_util_xdg.h" |
20 #include "base/nix/xdg_util.h" | 20 #include "base/nix/xdg_util.h" |
21 #include "base/stl_util.h" | 21 #include "base/stl_util.h" |
22 #include "base/strings/string_split.h" | 22 #include "base/strings/string_split.h" |
23 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
24 #include "chrome/browser/themes/theme_properties.h" | 24 #include "chrome/browser/themes/theme_properties.h" |
25 #include "chrome/browser/ui/libgtkui/app_indicator_icon.h" | 25 #include "chrome/browser/ui/libgtkui/app_indicator_icon.h" |
26 #include "chrome/browser/ui/libgtkui/gtk2_event_loop.h" | 26 #include "chrome/browser/ui/libgtkui/gtk_event_loop.h" |
27 #include "chrome/browser/ui/libgtkui/gtk2_key_bindings_handler.h" | 27 #include "chrome/browser/ui/libgtkui/gtk_key_bindings_handler.h" |
28 #include "chrome/browser/ui/libgtkui/gtk2_status_icon.h" | 28 #include "chrome/browser/ui/libgtkui/gtk_status_icon.h" |
29 #include "chrome/browser/ui/libgtkui/gtk2_util.h" | 29 #include "chrome/browser/ui/libgtkui/gtk_util.h" |
30 #include "chrome/browser/ui/libgtkui/native_theme_gtk2.h" | 30 #include "chrome/browser/ui/libgtkui/native_theme_gtk.h" |
31 #include "chrome/browser/ui/libgtkui/print_dialog_gtk2.h" | 31 #include "chrome/browser/ui/libgtkui/print_dialog_gtk.h" |
32 #include "chrome/browser/ui/libgtkui/printing_gtk2_util.h" | 32 #include "chrome/browser/ui/libgtkui/printing_gtk_util.h" |
33 #include "chrome/browser/ui/libgtkui/select_file_dialog_impl.h" | 33 #include "chrome/browser/ui/libgtkui/select_file_dialog_impl.h" |
34 #include "chrome/browser/ui/libgtkui/skia_utils_gtk2.h" | 34 #include "chrome/browser/ui/libgtkui/skia_utils_gtk.h" |
35 #include "chrome/browser/ui/libgtkui/unity_service.h" | 35 #include "chrome/browser/ui/libgtkui/unity_service.h" |
36 #include "chrome/browser/ui/libgtkui/x11_input_method_context_impl_gtk2.h" | 36 #include "chrome/browser/ui/libgtkui/x11_input_method_context_impl_gtk.h" |
37 #include "chrome/grit/theme_resources.h" | 37 #include "chrome/grit/theme_resources.h" |
38 #include "components/grit/components_scaled_resources.h" | 38 #include "components/grit/components_scaled_resources.h" |
39 #include "third_party/skia/include/core/SkBitmap.h" | 39 #include "third_party/skia/include/core/SkBitmap.h" |
40 #include "third_party/skia/include/core/SkCanvas.h" | 40 #include "third_party/skia/include/core/SkCanvas.h" |
41 #include "third_party/skia/include/core/SkColor.h" | 41 #include "third_party/skia/include/core/SkColor.h" |
42 #include "third_party/skia/include/core/SkShader.h" | 42 #include "third_party/skia/include/core/SkShader.h" |
43 #include "ui/base/resource/resource_bundle.h" | 43 #include "ui/base/resource/resource_bundle.h" |
44 #include "ui/display/display.h" | 44 #include "ui/display/display.h" |
45 #include "ui/gfx/canvas.h" | 45 #include "ui/gfx/canvas.h" |
46 #include "ui/gfx/geometry/rect.h" | 46 #include "ui/gfx/geometry/rect.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 123 |
124 gtk_widget_set_size_request(button, width, height); | 124 gtk_widget_set_size_request(button, width, height); |
125 gtk_container_add(GTK_CONTAINER(window), button); | 125 gtk_container_add(GTK_CONTAINER(window), button); |
126 | 126 |
127 if (is_blue_) | 127 if (is_blue_) |
128 TurnButtonBlue(button); | 128 TurnButtonBlue(button); |
129 | 129 |
130 gtk_widget_show_all(window); | 130 gtk_widget_show_all(window); |
131 | 131 |
132 cairo_surface_t* surface = cairo_image_surface_create_for_data( | 132 cairo_surface_t* surface = cairo_image_surface_create_for_data( |
133 static_cast<unsigned char*>(border.getAddr(0, 0)), | 133 static_cast<unsigned char*>(border.getAddr(0, 0)), CAIRO_FORMAT_ARGB32, |
134 CAIRO_FORMAT_ARGB32, width, height, width * 4); | 134 width, height, width * 4); |
135 cairo_t* cr = cairo_create(surface); | 135 cairo_t* cr = cairo_create(surface); |
136 | 136 |
137 #if GTK_MAJOR_VERSION == 2 | 137 #if GTK_MAJOR_VERSION == 2 |
138 if (focus_) | 138 if (focus_) |
139 GTK_WIDGET_SET_FLAGS(button, GTK_HAS_FOCUS); | 139 GTK_WIDGET_SET_FLAGS(button, GTK_HAS_FOCUS); |
140 | 140 |
141 int w, h; | 141 int w, h; |
142 GdkPixmap* pixmap; | 142 GdkPixmap* pixmap; |
143 | 143 |
144 { | 144 { |
(...skipping 10 matching lines...) Expand all Loading... |
155 gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0); | 155 gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0); |
156 cairo_paint(cr); | 156 cairo_paint(cr); |
157 | 157 |
158 g_object_unref(pixbuf); | 158 g_object_unref(pixbuf); |
159 g_object_unref(pixmap); | 159 g_object_unref(pixmap); |
160 #else | 160 #else |
161 gtk_widget_draw(button, cr); | 161 gtk_widget_draw(button, cr); |
162 | 162 |
163 // There's probably a better way to do this | 163 // There's probably a better way to do this |
164 if (focus_) | 164 if (focus_) |
165 gtk_render_focus(gtk_widget_get_style_context(button), cr, 0, 0, | 165 gtk_render_focus(gtk_widget_get_style_context(button), cr, 0, 0, width, |
166 width, height); | 166 height); |
167 #endif | 167 #endif |
168 | 168 |
169 cairo_destroy(cr); | 169 cairo_destroy(cr); |
170 cairo_surface_destroy(surface); | 170 cairo_surface_destroy(surface); |
171 | 171 |
172 gtk_widget_destroy(window); | 172 gtk_widget_destroy(window); |
173 | 173 |
174 return gfx::ImageSkiaRep(border, scale); | 174 return gfx::ImageSkiaRep(border, scale); |
175 } | 175 } |
176 | 176 |
(...skipping 19 matching lines...) Expand all Loading... |
196 canvas->DrawImageInt(image, 0, 0); | 196 canvas->DrawImageInt(image, 0, 0); |
197 } | 197 } |
198 | 198 |
199 private: | 199 private: |
200 std::string idr_; | 200 std::string idr_; |
201 | 201 |
202 DISALLOW_COPY_AND_ASSIGN(GtkButtonPainter); | 202 DISALLOW_COPY_AND_ASSIGN(GtkButtonPainter); |
203 }; | 203 }; |
204 | 204 |
205 struct GObjectDeleter { | 205 struct GObjectDeleter { |
206 void operator()(void* ptr) { | 206 void operator()(void* ptr) { g_object_unref(ptr); } |
207 g_object_unref(ptr); | |
208 } | |
209 }; | 207 }; |
210 struct GtkIconInfoDeleter { | 208 struct GtkIconInfoDeleter { |
211 void operator()(GtkIconInfo* ptr) { | 209 void operator()(GtkIconInfo* ptr) { |
212 G_GNUC_BEGIN_IGNORE_DEPRECATIONS | 210 G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
213 gtk_icon_info_free(ptr); | 211 gtk_icon_info_free(ptr); |
214 G_GNUC_END_IGNORE_DEPRECATIONS | 212 G_GNUC_END_IGNORE_DEPRECATIONS |
215 } | 213 } |
216 }; | 214 }; |
217 typedef std::unique_ptr<GIcon, GObjectDeleter> ScopedGIcon; | 215 typedef std::unique_ptr<GIcon, GObjectDeleter> ScopedGIcon; |
218 typedef std::unique_ptr<GtkIconInfo, GtkIconInfoDeleter> ScopedGtkIconInfo; | 216 typedef std::unique_ptr<GtkIconInfo, GtkIconInfoDeleter> ScopedGtkIconInfo; |
219 typedef std::unique_ptr<GdkPixbuf, GObjectDeleter> ScopedGdkPixbuf; | 217 typedef std::unique_ptr<GdkPixbuf, GObjectDeleter> ScopedGdkPixbuf; |
220 | 218 |
221 // Prefix for app indicator ids | 219 // Prefix for app indicator ids |
222 const char kAppIndicatorIdPrefix[] = "chrome_app_indicator_"; | 220 const char kAppIndicatorIdPrefix[] = "chrome_app_indicator_"; |
223 | 221 |
224 // Number of app indicators used (used as part of app-indicator id). | 222 // Number of app indicators used (used as part of app-indicator id). |
225 int indicators_count; | 223 int indicators_count; |
226 | 224 |
227 // The unknown content type. | 225 // The unknown content type. |
228 const char* kUnknownContentType = "application/octet-stream"; | 226 const char* kUnknownContentType = "application/octet-stream"; |
229 | 227 |
230 // TODO(erg): ThemeService has a whole interface just for reading default | 228 // TODO(erg): ThemeService has a whole interface just for reading default |
231 // constants. Figure out what to do with that more long term; for now, just | 229 // constants. Figure out what to do with that more long term; for now, just |
232 // copy the constants themselves here. | 230 // copy the constants themselves here. |
233 // | 231 // |
234 // Default tints. | 232 // Default tints. |
235 const color_utils::HSL kDefaultTintFrameIncognito = { -1, 0.2f, 0.35f }; | 233 const color_utils::HSL kDefaultTintFrameIncognito = {-1, 0.2f, 0.35f}; |
236 const color_utils::HSL kDefaultTintFrameIncognitoInactive = { -1, 0.3f, 0.6f }; | 234 const color_utils::HSL kDefaultTintFrameIncognitoInactive = {-1, 0.3f, 0.6f}; |
237 | 235 |
238 #if GTK_MAJOR_VERSION == 3 | 236 #if GTK_MAJOR_VERSION == 3 |
239 const color_utils::HSL kDefaultTintFrameInactive = { -1, -1, 0.75f }; | 237 const color_utils::HSL kDefaultTintFrameInactive = {-1, -1, 0.75f}; |
240 #endif // GTK_MAJOR_VERSION == 3 | 238 #endif // GTK_MAJOR_VERSION == 3 |
241 | 239 |
242 // Picks a button tint from a set of background colors. While | 240 // Picks a button tint from a set of background colors. While |
243 // |accent_color| will usually be the same color through a theme, this | 241 // |accent_color| will usually be the same color through a theme, this |
244 // function will get called with the normal GtkLabel |text_color|/GtkWindow | 242 // function will get called with the normal GtkLabel |text_color|/GtkWindow |
245 // |background_color| pair and the GtkEntry |text_color|/|background_color| | 243 // |background_color| pair and the GtkEntry |text_color|/|background_color| |
246 // pair. While 3/4 of the time the resulting tint will be the same, themes that | 244 // pair. While 3/4 of the time the resulting tint will be the same, themes that |
247 // have a dark window background (with light text) and a light text entry (with | 245 // have a dark window background (with light text) and a light text entry (with |
248 // dark text) will get better icons with this separated out. | 246 // dark text) will get better icons with this separated out. |
249 void PickButtonTintFromColors(SkColor accent_color, | 247 void PickButtonTintFromColors(SkColor accent_color, |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 } | 417 } |
420 | 418 |
421 Gtk2UI::~Gtk2UI() {} | 419 Gtk2UI::~Gtk2UI() {} |
422 | 420 |
423 void OnThemeChanged(GObject* obj, GParamSpec* param, Gtk2UI* gtkui) { | 421 void OnThemeChanged(GObject* obj, GParamSpec* param, Gtk2UI* gtkui) { |
424 gtkui->ResetStyle(); | 422 gtkui->ResetStyle(); |
425 } | 423 } |
426 | 424 |
427 void Gtk2UI::Initialize() { | 425 void Gtk2UI::Initialize() { |
428 GtkSettings* settings = gtk_settings_get_default(); | 426 GtkSettings* settings = gtk_settings_get_default(); |
429 g_signal_connect_after(settings, | 427 g_signal_connect_after(settings, "notify::gtk-theme-name", |
430 "notify::gtk-theme-name", | 428 G_CALLBACK(OnThemeChanged), this); |
431 G_CALLBACK(OnThemeChanged), | 429 g_signal_connect_after(settings, "notify::gtk-icon-theme-name", |
432 this); | 430 G_CALLBACK(OnThemeChanged), this); |
433 g_signal_connect_after(settings, | |
434 "notify::gtk-icon-theme-name", | |
435 G_CALLBACK(OnThemeChanged), | |
436 this); | |
437 | 431 |
438 LoadGtkValues(); | 432 LoadGtkValues(); |
439 | 433 |
440 LoadCursorTheme(); | 434 LoadCursorTheme(); |
441 | 435 |
442 #if defined(ENABLE_BASIC_PRINTING) | 436 #if defined(ENABLE_BASIC_PRINTING) |
443 printing::PrintingContextLinux::SetCreatePrintDialogFunction( | 437 printing::PrintingContextLinux::SetCreatePrintDialogFunction( |
444 &PrintDialogGtk2::CreatePrintDialog); | 438 &PrintDialogGtk2::CreatePrintDialog); |
445 printing::PrintingContextLinux::SetPdfPaperSizeFunction( | 439 printing::PrintingContextLinux::SetPdfPaperSizeFunction( |
446 &GetPdfPaperSizeDeviceUnitsGtk); | 440 &GetPdfPaperSizeDeviceUnitsGtk); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 ++indicators_count; | 586 ++indicators_count; |
593 return std::unique_ptr<views::StatusIconLinux>(new AppIndicatorIcon( | 587 return std::unique_ptr<views::StatusIconLinux>(new AppIndicatorIcon( |
594 base::StringPrintf("%s%d", kAppIndicatorIdPrefix, indicators_count), | 588 base::StringPrintf("%s%d", kAppIndicatorIdPrefix, indicators_count), |
595 image, tool_tip)); | 589 image, tool_tip)); |
596 } else { | 590 } else { |
597 return std::unique_ptr<views::StatusIconLinux>( | 591 return std::unique_ptr<views::StatusIconLinux>( |
598 new Gtk2StatusIcon(image, tool_tip)); | 592 new Gtk2StatusIcon(image, tool_tip)); |
599 } | 593 } |
600 } | 594 } |
601 | 595 |
602 gfx::Image Gtk2UI::GetIconForContentType( | 596 gfx::Image Gtk2UI::GetIconForContentType(const std::string& content_type, |
603 const std::string& content_type, | 597 int size) const { |
604 int size) const { | |
605 // This call doesn't take a reference. | 598 // This call doesn't take a reference. |
606 GtkIconTheme* theme = gtk_icon_theme_get_default(); | 599 GtkIconTheme* theme = gtk_icon_theme_get_default(); |
607 | 600 |
608 std::string content_types[] = { | 601 std::string content_types[] = {content_type, kUnknownContentType}; |
609 content_type, kUnknownContentType | |
610 }; | |
611 | 602 |
612 for (size_t i = 0; i < arraysize(content_types); ++i) { | 603 for (size_t i = 0; i < arraysize(content_types); ++i) { |
613 ScopedGIcon icon(g_content_type_get_icon(content_types[i].c_str())); | 604 ScopedGIcon icon(g_content_type_get_icon(content_types[i].c_str())); |
614 ScopedGtkIconInfo icon_info( | 605 ScopedGtkIconInfo icon_info(gtk_icon_theme_lookup_by_gicon( |
615 gtk_icon_theme_lookup_by_gicon( | 606 theme, icon.get(), size, |
616 theme, icon.get(), size, | 607 static_cast<GtkIconLookupFlags>(GTK_ICON_LOOKUP_FORCE_SIZE))); |
617 static_cast<GtkIconLookupFlags>(GTK_ICON_LOOKUP_FORCE_SIZE))); | |
618 if (!icon_info) | 608 if (!icon_info) |
619 continue; | 609 continue; |
620 ScopedGdkPixbuf pixbuf(gtk_icon_info_load_icon(icon_info.get(), NULL)); | 610 ScopedGdkPixbuf pixbuf(gtk_icon_info_load_icon(icon_info.get(), NULL)); |
621 if (!pixbuf) | 611 if (!pixbuf) |
622 continue; | 612 continue; |
623 | 613 |
624 SkBitmap bitmap = GdkPixbufToImageSkia(pixbuf.get()); | 614 SkBitmap bitmap = GdkPixbufToImageSkia(pixbuf.get()); |
625 DCHECK_EQ(size, bitmap.width()); | 615 DCHECK_EQ(size, bitmap.width()); |
626 DCHECK_EQ(size, bitmap.height()); | 616 DCHECK_EQ(size, bitmap.height()); |
627 gfx::ImageSkia image_skia = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | 617 gfx::ImageSkia image_skia = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
(...skipping 13 matching lines...) Expand all Loading... |
641 new views::LabelButtonAssetBorder(owning_button->style())); | 631 new views::LabelButtonAssetBorder(owning_button->style())); |
642 | 632 |
643 gtk_border->set_insets(border->GetInsets()); | 633 gtk_border->set_insets(border->GetInsets()); |
644 | 634 |
645 static struct { | 635 static struct { |
646 const char* idr; | 636 const char* idr; |
647 const char* idr_blue; | 637 const char* idr_blue; |
648 bool focus; | 638 bool focus; |
649 views::Button::ButtonState state; | 639 views::Button::ButtonState state; |
650 } const paintstate[] = { | 640 } const paintstate[] = { |
651 { "IDR_BUTTON_NORMAL", | 641 { |
652 "IDR_BLUE_BUTTON_NORMAL", | 642 "IDR_BUTTON_NORMAL", "IDR_BLUE_BUTTON_NORMAL", false, |
653 false, views::Button::STATE_NORMAL, }, | 643 views::Button::STATE_NORMAL, |
654 { "IDR_BUTTON_HOVER", | 644 }, |
655 "IDR_BLUE_BUTTON_HOVER", | 645 { |
656 false, views::Button::STATE_HOVERED, }, | 646 "IDR_BUTTON_HOVER", "IDR_BLUE_BUTTON_HOVER", false, |
657 { "IDR_BUTTON_PRESSED", | 647 views::Button::STATE_HOVERED, |
658 "IDR_BLUE_BUTTON_PRESSED", | 648 }, |
659 false, views::Button::STATE_PRESSED, }, | 649 { |
660 { "IDR_BUTTON_DISABLED", | 650 "IDR_BUTTON_PRESSED", "IDR_BLUE_BUTTON_PRESSED", false, |
661 "IDR_BLUE_BUTTON_DISABLED", | 651 views::Button::STATE_PRESSED, |
662 false, views::Button::STATE_DISABLED, }, | 652 }, |
| 653 { |
| 654 "IDR_BUTTON_DISABLED", "IDR_BLUE_BUTTON_DISABLED", false, |
| 655 views::Button::STATE_DISABLED, |
| 656 }, |
663 | 657 |
664 { "IDR_BUTTON_FOCUSED_NORMAL", | 658 { |
665 "IDR_BLUE_BUTTON_FOCUSED_NORMAL", | 659 "IDR_BUTTON_FOCUSED_NORMAL", "IDR_BLUE_BUTTON_FOCUSED_NORMAL", true, |
666 true, views::Button::STATE_NORMAL, }, | 660 views::Button::STATE_NORMAL, |
667 { "IDR_BUTTON_FOCUSED_HOVER", | 661 }, |
668 "IDR_BLUE_BUTTON_FOCUSED_HOVER", | 662 { |
669 true, views::Button::STATE_HOVERED, }, | 663 "IDR_BUTTON_FOCUSED_HOVER", "IDR_BLUE_BUTTON_FOCUSED_HOVER", true, |
670 { "IDR_BUTTON_FOCUSED_PRESSED", | 664 views::Button::STATE_HOVERED, |
671 "IDR_BLUE_BUTTON_FOCUSED_PRESSED", | 665 }, |
672 true, views::Button::STATE_PRESSED, }, | 666 { |
673 { "IDR_BUTTON_DISABLED", | 667 "IDR_BUTTON_FOCUSED_PRESSED", "IDR_BLUE_BUTTON_FOCUSED_PRESSED", true, |
674 "IDR_BLUE_BUTTON_DISABLED", | 668 views::Button::STATE_PRESSED, |
675 true, views::Button::STATE_DISABLED, }, | 669 }, |
| 670 { |
| 671 "IDR_BUTTON_DISABLED", "IDR_BLUE_BUTTON_DISABLED", true, |
| 672 views::Button::STATE_DISABLED, |
| 673 }, |
676 }; | 674 }; |
677 | 675 |
678 bool is_blue = | 676 bool is_blue = |
679 owning_button->GetClassName() == views::BlueButton::kViewClassName; | 677 owning_button->GetClassName() == views::BlueButton::kViewClassName; |
680 | 678 |
681 for (unsigned i = 0; i < arraysize(paintstate); i++) { | 679 for (unsigned i = 0; i < arraysize(paintstate); i++) { |
682 views::Painter* painter = nullptr; | 680 views::Painter* painter = nullptr; |
683 | 681 |
684 if (border->PaintsButtonState(paintstate[i].focus, paintstate[i].state)) { | 682 if (border->PaintsButtonState(paintstate[i].focus, paintstate[i].state)) { |
685 std::string idr = is_blue ? paintstate[i].idr_blue : paintstate[i].idr; | 683 std::string idr = is_blue ? paintstate[i].idr_blue : paintstate[i].idr; |
686 painter = new GtkButtonPainter(idr); | 684 painter = new GtkButtonPainter(idr); |
687 } | 685 } |
688 | 686 |
689 gtk_border->SetPainter(paintstate[i].focus, paintstate[i].state, painter); | 687 gtk_border->SetPainter(paintstate[i].focus, paintstate[i].state, painter); |
690 } | 688 } |
691 | 689 |
692 return std::move(gtk_border); | 690 return std::move(gtk_border); |
693 } | 691 } |
694 | 692 |
695 void Gtk2UI::AddWindowButtonOrderObserver( | 693 void Gtk2UI::AddWindowButtonOrderObserver( |
696 views::WindowButtonOrderObserver* observer) { | 694 views::WindowButtonOrderObserver* observer) { |
697 if (!leading_buttons_.empty() || !trailing_buttons_.empty()) { | 695 if (!leading_buttons_.empty() || !trailing_buttons_.empty()) { |
698 observer->OnWindowButtonOrderingChange(leading_buttons_, | 696 observer->OnWindowButtonOrderingChange(leading_buttons_, trailing_buttons_); |
699 trailing_buttons_); | |
700 } | 697 } |
701 | 698 |
702 observer_list_.AddObserver(observer); | 699 observer_list_.AddObserver(observer); |
703 } | 700 } |
704 | 701 |
705 void Gtk2UI::RemoveWindowButtonOrderObserver( | 702 void Gtk2UI::RemoveWindowButtonOrderObserver( |
706 views::WindowButtonOrderObserver* observer) { | 703 views::WindowButtonOrderObserver* observer) { |
707 observer_list_.RemoveObserver(observer); | 704 observer_list_.RemoveObserver(observer); |
708 } | 705 } |
709 | 706 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 GetNormalButtonTintHSL(&button_tint_); | 816 GetNormalButtonTintHSL(&button_tint_); |
820 GetNormalEntryForegroundHSL(&entry_tint_); | 817 GetNormalEntryForegroundHSL(&entry_tint_); |
821 GetSelectedEntryForegroundHSL(&selected_entry_tint_); | 818 GetSelectedEntryForegroundHSL(&selected_entry_tint_); |
822 | 819 |
823 // We pick the text and background colors for the NTP out of the colors for a | 820 // We pick the text and background colors for the NTP out of the colors for a |
824 // GtkEntry. We do this because GtkEntries background color is never the same | 821 // GtkEntry. We do this because GtkEntries background color is never the same |
825 // as |toolbar_color|, is usually a white, and when it isn't a white, | 822 // as |toolbar_color|, is usually a white, and when it isn't a white, |
826 // provides sufficient contrast to |toolbar_color|. Try this out with | 823 // provides sufficient contrast to |toolbar_color|. Try this out with |
827 // Darklooks, HighContrastInverse or ThinIce. | 824 // Darklooks, HighContrastInverse or ThinIce. |
828 | 825 |
829 SkColor ntp_background = | 826 SkColor ntp_background = theme->GetSystemColor( |
830 theme->GetSystemColor( | 827 ui::NativeTheme::kColorId_TextfieldDefaultBackground); |
831 ui::NativeTheme::kColorId_TextfieldDefaultBackground); | |
832 SkColor ntp_foreground = | 828 SkColor ntp_foreground = |
833 theme->GetSystemColor( | 829 theme->GetSystemColor(ui::NativeTheme::kColorId_TextfieldDefaultColor); |
834 ui::NativeTheme::kColorId_TextfieldDefaultColor); | |
835 | 830 |
836 colors_[ThemeProperties::COLOR_NTP_BACKGROUND] = ntp_background; | 831 colors_[ThemeProperties::COLOR_NTP_BACKGROUND] = ntp_background; |
837 colors_[ThemeProperties::COLOR_NTP_TEXT] = ntp_foreground; | 832 colors_[ThemeProperties::COLOR_NTP_TEXT] = ntp_foreground; |
838 | 833 |
839 // The NTP header is the color that surrounds the current active thumbnail on | 834 // The NTP header is the color that surrounds the current active thumbnail on |
840 // the NTP, and acts as the border of the "Recent Links" box. It would be | 835 // the NTP, and acts as the border of the "Recent Links" box. It would be |
841 // awesome if they were separated so we could use GetBorderColor() for the | 836 // awesome if they were separated so we could use GetBorderColor() for the |
842 // border around the "Recent Links" section, but matching the frame color is | 837 // border around the "Recent Links" section, but matching the frame color is |
843 // more important. | 838 // more important. |
844 | 839 |
(...skipping 10 matching lines...) Expand all Loading... |
855 colors_[ThemeProperties::COLOR_NTP_SECTION_LINK] = link_color; | 850 colors_[ThemeProperties::COLOR_NTP_SECTION_LINK] = link_color; |
856 colors_[ThemeProperties::COLOR_NTP_SECTION_LINK_UNDERLINE] = link_color; | 851 colors_[ThemeProperties::COLOR_NTP_SECTION_LINK_UNDERLINE] = link_color; |
857 | 852 |
858 // Generate the colors that we pass to WebKit. | 853 // Generate the colors that we pass to WebKit. |
859 focus_ring_color_ = frame_color; | 854 focus_ring_color_ = frame_color; |
860 | 855 |
861 SetScrollbarColors(); | 856 SetScrollbarColors(); |
862 | 857 |
863 // Some GTK themes only define the text selection colors on the GtkEntry | 858 // Some GTK themes only define the text selection colors on the GtkEntry |
864 // class, so we need to use that for getting selection colors. | 859 // class, so we need to use that for getting selection colors. |
865 active_selection_bg_color_ = | 860 active_selection_bg_color_ = theme->GetSystemColor( |
866 theme->GetSystemColor( | 861 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused); |
867 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused); | |
868 active_selection_fg_color_ = | 862 active_selection_fg_color_ = |
869 theme->GetSystemColor( | 863 theme->GetSystemColor(ui::NativeTheme::kColorId_TextfieldSelectionColor); |
870 ui::NativeTheme::kColorId_TextfieldSelectionColor); | 864 inactive_selection_bg_color_ = theme->GetSystemColor( |
871 inactive_selection_bg_color_ = | 865 ui::NativeTheme::kColorId_TextfieldReadOnlyBackground); |
872 theme->GetSystemColor( | |
873 ui::NativeTheme::kColorId_TextfieldReadOnlyBackground); | |
874 inactive_selection_fg_color_ = | 866 inactive_selection_fg_color_ = |
875 theme->GetSystemColor( | 867 theme->GetSystemColor(ui::NativeTheme::kColorId_TextfieldReadOnlyColor); |
876 ui::NativeTheme::kColorId_TextfieldReadOnlyColor); | |
877 | 868 |
878 colors_[ThemeProperties::COLOR_TAB_THROBBER_SPINNING] = | 869 colors_[ThemeProperties::COLOR_TAB_THROBBER_SPINNING] = |
879 theme->GetSystemColor(ui::NativeTheme::kColorId_ThrobberSpinningColor); | 870 theme->GetSystemColor(ui::NativeTheme::kColorId_ThrobberSpinningColor); |
880 colors_[ThemeProperties::COLOR_TAB_THROBBER_WAITING] = | 871 colors_[ThemeProperties::COLOR_TAB_THROBBER_WAITING] = |
881 theme->GetSystemColor(ui::NativeTheme::kColorId_ThrobberWaitingColor); | 872 theme->GetSystemColor(ui::NativeTheme::kColorId_ThrobberWaitingColor); |
882 } | 873 } |
883 | 874 |
884 void Gtk2UI::LoadCursorTheme() { | 875 void Gtk2UI::LoadCursorTheme() { |
885 GtkSettings* settings = gtk_settings_get_default(); | 876 GtkSettings* settings = gtk_settings_get_default(); |
886 | 877 |
887 gchar* theme = nullptr; | 878 gchar* theme = nullptr; |
888 gint size = 0; | 879 gint size = 0; |
889 g_object_get(settings, | 880 g_object_get(settings, |
890 "gtk-cursor-theme-name", &theme, | 881 "gtk-cursor-theme-name", &theme, |
891 "gtk-cursor-theme-size", &size, | 882 "gtk-cursor-theme-size", &size, |
892 nullptr); | 883 nullptr); |
893 | 884 |
894 if (theme) | 885 if (theme) |
895 XcursorSetTheme(gfx::GetXDisplay(), theme); | 886 XcursorSetTheme(gfx::GetXDisplay(), theme); |
896 if (size) | 887 if (size) |
897 XcursorSetDefaultSize(gfx::GetXDisplay(), size); | 888 XcursorSetDefaultSize(gfx::GetXDisplay(), size); |
898 | 889 |
899 g_free(theme); | 890 g_free(theme); |
900 } | 891 } |
901 | 892 |
902 void Gtk2UI::BuildFrameColors() { | 893 void Gtk2UI::BuildFrameColors() { |
903 #if GTK_MAJOR_VERSION == 2 | 894 #if GTK_MAJOR_VERSION == 2 |
904 NativeThemeGtk2* theme = NativeThemeGtk2::instance(); | 895 NativeThemeGtk2* theme = NativeThemeGtk2::instance(); |
905 color_utils::HSL kDefaultFrameShift = { -1, -1, 0.4 }; | 896 color_utils::HSL kDefaultFrameShift = {-1, -1, 0.4}; |
906 SkColor frame_color = | 897 SkColor frame_color = |
907 theme->GetSystemColor(ui::NativeTheme::kColorId_WindowBackground); | 898 theme->GetSystemColor(ui::NativeTheme::kColorId_WindowBackground); |
908 frame_color = color_utils::HSLShift(frame_color, kDefaultFrameShift); | 899 frame_color = color_utils::HSLShift(frame_color, kDefaultFrameShift); |
909 theme->GetChromeStyleColor("frame-color", &frame_color); | 900 theme->GetChromeStyleColor("frame-color", &frame_color); |
910 colors_[ThemeProperties::COLOR_FRAME] = frame_color; | 901 colors_[ThemeProperties::COLOR_FRAME] = frame_color; |
911 | 902 |
912 GtkStyle* style = gtk_rc_get_style(theme->GetWindow()); | 903 GtkStyle* style = gtk_rc_get_style(theme->GetWindow()); |
913 SkColor temp_color = color_utils::HSLShift( | 904 SkColor temp_color = color_utils::HSLShift( |
914 GdkColorToSkColor(style->bg[GTK_STATE_INSENSITIVE]), | 905 GdkColorToSkColor(style->bg[GTK_STATE_INSENSITIVE]), kDefaultFrameShift); |
915 kDefaultFrameShift); | |
916 theme->GetChromeStyleColor("inactive-frame-color", &temp_color); | 906 theme->GetChromeStyleColor("inactive-frame-color", &temp_color); |
917 colors_[ThemeProperties::COLOR_FRAME_INACTIVE] = temp_color; | 907 colors_[ThemeProperties::COLOR_FRAME_INACTIVE] = temp_color; |
918 | 908 |
919 temp_color = color_utils::HSLShift( | 909 temp_color = color_utils::HSLShift(frame_color, kDefaultTintFrameIncognito); |
920 frame_color, | |
921 kDefaultTintFrameIncognito); | |
922 theme->GetChromeStyleColor("incognito-frame-color", &temp_color); | 910 theme->GetChromeStyleColor("incognito-frame-color", &temp_color); |
923 colors_[ThemeProperties::COLOR_FRAME_INCOGNITO] = temp_color; | 911 colors_[ThemeProperties::COLOR_FRAME_INCOGNITO] = temp_color; |
924 | 912 |
925 temp_color = color_utils::HSLShift( | 913 temp_color = |
926 frame_color, | 914 color_utils::HSLShift(frame_color, kDefaultTintFrameIncognitoInactive); |
927 kDefaultTintFrameIncognitoInactive); | |
928 theme->GetChromeStyleColor("incognito-inactive-frame-color", &temp_color); | 915 theme->GetChromeStyleColor("incognito-inactive-frame-color", &temp_color); |
929 colors_[ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE] = temp_color; | 916 colors_[ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE] = temp_color; |
930 #else | 917 #else |
931 auto set_frame_color = [this](int color_id) { | 918 auto set_frame_color = [this](int color_id) { |
932 // Render a GtkHeaderBar as our title bar, cropping out any curved edges | 919 // Render a GtkHeaderBar as our title bar, cropping out any curved edges |
933 // on the left and right sides. Also remove the bottom border for good | 920 // on the left and right sides. Also remove the bottom border for good |
934 // measure. | 921 // measure. |
935 SkBitmap bitmap; | 922 SkBitmap bitmap; |
936 bitmap.allocN32Pixels(1, 1); | 923 bitmap.allocN32Pixels(1, 1); |
937 bitmap.eraseColor(0); | 924 bitmap.eraseColor(0); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
982 set_frame_color(ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE); | 969 set_frame_color(ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE); |
983 #endif | 970 #endif |
984 } | 971 } |
985 | 972 |
986 void Gtk2UI::GetNormalButtonTintHSL(color_utils::HSL* tint) const { | 973 void Gtk2UI::GetNormalButtonTintHSL(color_utils::HSL* tint) const { |
987 NativeThemeGtk2* theme = NativeThemeGtk2::instance(); | 974 NativeThemeGtk2* theme = NativeThemeGtk2::instance(); |
988 | 975 |
989 SkColor accent_color = | 976 SkColor accent_color = |
990 theme->GetSystemColor(ui::NativeTheme::kColorId_ProminentButtonColor); | 977 theme->GetSystemColor(ui::NativeTheme::kColorId_ProminentButtonColor); |
991 SkColor text_color = | 978 SkColor text_color = |
992 theme->GetSystemColor( | 979 theme->GetSystemColor(ui::NativeTheme::kColorId_LabelEnabledColor); |
993 ui::NativeTheme::kColorId_LabelEnabledColor); | |
994 SkColor base_color = | 980 SkColor base_color = |
995 theme->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground); | 981 theme->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground); |
996 | 982 |
997 PickButtonTintFromColors(accent_color, text_color, base_color, tint); | 983 PickButtonTintFromColors(accent_color, text_color, base_color, tint); |
998 } | 984 } |
999 | 985 |
1000 void Gtk2UI::GetNormalEntryForegroundHSL(color_utils::HSL* tint) const { | 986 void Gtk2UI::GetNormalEntryForegroundHSL(color_utils::HSL* tint) const { |
1001 NativeThemeGtk2* theme = NativeThemeGtk2::instance(); | 987 NativeThemeGtk2* theme = NativeThemeGtk2::instance(); |
1002 | 988 |
1003 SkColor accent_color = | 989 SkColor accent_color = |
1004 theme->GetSystemColor(ui::NativeTheme::kColorId_ProminentButtonColor); | 990 theme->GetSystemColor(ui::NativeTheme::kColorId_ProminentButtonColor); |
1005 SkColor text_color = | 991 SkColor text_color = |
1006 theme->GetSystemColor( | 992 theme->GetSystemColor(ui::NativeTheme::kColorId_TextfieldDefaultColor); |
1007 ui::NativeTheme::kColorId_TextfieldDefaultColor); | 993 SkColor base_color = theme->GetSystemColor( |
1008 SkColor base_color = | 994 ui::NativeTheme::kColorId_TextfieldDefaultBackground); |
1009 theme->GetSystemColor( | |
1010 ui::NativeTheme::kColorId_TextfieldDefaultBackground); | |
1011 | 995 |
1012 PickButtonTintFromColors(accent_color, text_color, base_color, tint); | 996 PickButtonTintFromColors(accent_color, text_color, base_color, tint); |
1013 } | 997 } |
1014 | 998 |
1015 void Gtk2UI::GetSelectedEntryForegroundHSL(color_utils::HSL* tint) const { | 999 void Gtk2UI::GetSelectedEntryForegroundHSL(color_utils::HSL* tint) const { |
1016 // The simplest of all the tints. We just use the selected text in the entry | 1000 // The simplest of all the tints. We just use the selected text in the entry |
1017 // since the icons tinted this way will only be displayed against | 1001 // since the icons tinted this way will only be displayed against |
1018 // base[GTK_STATE_SELECTED]. | 1002 // base[GTK_STATE_SELECTED]. |
1019 SkColor color = | 1003 SkColor color = NativeThemeGtk2::instance()->GetSystemColor( |
1020 NativeThemeGtk2::instance()->GetSystemColor( | 1004 ui::NativeTheme::kColorId_TextfieldSelectionColor); |
1021 ui::NativeTheme::kColorId_TextfieldSelectionColor); | |
1022 | 1005 |
1023 color_utils::SkColorToHSL(color, tint); | 1006 color_utils::SkColorToHSL(color, tint); |
1024 } | 1007 } |
1025 | 1008 |
1026 void Gtk2UI::UpdateDefaultFont() { | 1009 void Gtk2UI::UpdateDefaultFont() { |
1027 PangoContext* pc = gtk_widget_get_pango_context( | 1010 PangoContext* pc = |
1028 NativeThemeGtk2::instance()->GetLabel()); | 1011 gtk_widget_get_pango_context(NativeThemeGtk2::instance()->GetLabel()); |
1029 const PangoFontDescription* desc = pango_context_get_font_description(pc); | 1012 const PangoFontDescription* desc = pango_context_get_font_description(pc); |
1030 | 1013 |
1031 // Use gfx::FontRenderParams to select a family and determine the rendering | 1014 // Use gfx::FontRenderParams to select a family and determine the rendering |
1032 // settings. | 1015 // settings. |
1033 gfx::FontRenderParamsQuery query; | 1016 gfx::FontRenderParamsQuery query; |
1034 query.families = base::SplitString(pango_font_description_get_family(desc), | 1017 query.families = |
1035 ",", base::TRIM_WHITESPACE, | 1018 base::SplitString(pango_font_description_get_family(desc), ",", |
1036 base::SPLIT_WANT_ALL); | 1019 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
1037 | 1020 |
1038 if (pango_font_description_get_size_is_absolute(desc)) { | 1021 if (pango_font_description_get_size_is_absolute(desc)) { |
1039 // If the size is absolute, it's specified in Pango units. There are | 1022 // If the size is absolute, it's specified in Pango units. There are |
1040 // PANGO_SCALE Pango units in a device unit (pixel). | 1023 // PANGO_SCALE Pango units in a device unit (pixel). |
1041 const int size_pixels = pango_font_description_get_size(desc) / PANGO_SCALE; | 1024 const int size_pixels = pango_font_description_get_size(desc) / PANGO_SCALE; |
1042 default_font_size_pixels_ = size_pixels; | 1025 default_font_size_pixels_ = size_pixels; |
1043 query.pixel_size = size_pixels; | 1026 query.pixel_size = size_pixels; |
1044 } else { | 1027 } else { |
1045 // Non-absolute sizes are in points (again scaled by PANGO_SIZE). | 1028 // Non-absolute sizes are in points (again scaled by PANGO_SIZE). |
1046 // Round the value when converting to pixels to match GTK's logic. | 1029 // Round the value when converting to pixels to match GTK's logic. |
1047 const double size_points = pango_font_description_get_size(desc) / | 1030 const double size_points = pango_font_description_get_size(desc) / |
1048 static_cast<double>(PANGO_SCALE); | 1031 static_cast<double>(PANGO_SCALE); |
1049 default_font_size_pixels_ = static_cast<int>( | 1032 default_font_size_pixels_ = static_cast<int>( |
1050 GetPixelsInPoint(device_scale_factor_) * size_points + 0.5); | 1033 GetPixelsInPoint(device_scale_factor_) * size_points + 0.5); |
1051 query.point_size = static_cast<int>(size_points); | 1034 query.point_size = static_cast<int>(size_points); |
1052 } | 1035 } |
1053 | 1036 |
1054 query.style = gfx::Font::NORMAL; | 1037 query.style = gfx::Font::NORMAL; |
1055 query.weight = | 1038 query.weight = |
1056 static_cast<gfx::Font::Weight>(pango_font_description_get_weight(desc)); | 1039 static_cast<gfx::Font::Weight>(pango_font_description_get_weight(desc)); |
1057 // TODO(davemoore): What about PANGO_STYLE_OBLIQUE? | 1040 // TODO(davemoore): What about PANGO_STYLE_OBLIQUE? |
1058 if (pango_font_description_get_style(desc) == PANGO_STYLE_ITALIC) | 1041 if (pango_font_description_get_style(desc) == PANGO_STYLE_ITALIC) |
(...skipping 23 matching lines...) Expand all Loading... |
1082 // Blacklist scaling factors <130% (crbug.com/484400) and round | 1065 // Blacklist scaling factors <130% (crbug.com/484400) and round |
1083 // to 1 decimal to prevent rendering problems (crbug.com/485183). | 1066 // to 1 decimal to prevent rendering problems (crbug.com/485183). |
1084 return scale < 1.3f ? 1.0f : roundf(scale * 10) / 10; | 1067 return scale < 1.3f ? 1.0f : roundf(scale * 10) / 10; |
1085 } | 1068 } |
1086 | 1069 |
1087 } // namespace libgtkui | 1070 } // namespace libgtkui |
1088 | 1071 |
1089 views::LinuxUI* BuildGtk2UI() { | 1072 views::LinuxUI* BuildGtk2UI() { |
1090 return new libgtkui::Gtk2UI; | 1073 return new libgtkui::Gtk2UI; |
1091 } | 1074 } |
OLD | NEW |