-
Notifications
You must be signed in to change notification settings - Fork 2
/
gtk2.patch
1748 lines (1698 loc) · 57.8 KB
/
gtk2.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
description: restore support for building against gtk2
author: Michael Gilbert <[email protected]>
origin: chromium 69 authors
--- a/build/config/linux/atk/BUILD.gn
+++ b/build/config/linux/atk/BUILD.gn
@@ -3,6 +3,7 @@
# found in the LICENSE file.
import("//build/config/features.gni")
+import("//build/config/linux/gtk/gtk.gni")
import("//build/config/linux/pkg_config.gni")
import("//build/config/ui.gni")
@@ -19,7 +20,6 @@ if (use_atk) {
pkg_config("atk_base") {
packages = [
"atk",
- "atk-bridge-2.0",
]
atk_lib_dir = exec_script(pkg_config_script,
pkg_config_args + [
@@ -29,7 +29,6 @@ pkg_config("atk_base") {
"string")
defines = [
"ATK_LIB_DIR=\"$atk_lib_dir\"",
- "USE_ATK_BRIDGE",
# The AtkValue interface methods we implement and test have been deprecated
# in favor of new API. But that new API cannot be used until corresponding
@@ -37,6 +36,10 @@ pkg_config("atk_base") {
# of ATK (i.e. < 2.12).
"ATK_DISABLE_DEPRECATION_WARNINGS",
]
+ if (gtk_version == 3) {
+ packages += [ "atk-bridge-2.0" ]
+ defines += [ "USE_ATK_BRIDGE" ]
+ }
}
# gn orders flags on a target before flags from configs. The default config
--- a/ui/accessibility/BUILD.gn
+++ b/ui/accessibility/BUILD.gn
@@ -4,6 +4,7 @@
import("//build/config/features.gni")
import("//build/config/jumbo.gni")
+import("//build/config/linux/gtk/gtk.gni")
import("//build/config/linux/pkg_config.gni")
import("//build/config/ui.gni")
import("//mojo/public/tools/bindings/mojom.gni")
@@ -170,13 +171,19 @@ jumbo_component("accessibility") {
sources += [
"platform/atk_util_auralinux.cc",
"platform/atk_util_auralinux.h",
- "platform/atk_util_auralinux_gtk.cc",
"platform/ax_platform_atk_hyperlink.cc",
"platform/ax_platform_atk_hyperlink.h",
"platform/ax_platform_node_auralinux.cc",
"platform/ax_platform_node_auralinux.h",
]
+ if (gtk_version == 2 ) {
+ sources += [ "platform/atk_util_auralinux_gtk2.cc" ]
+ }
+ if (gtk_version == 3) {
+ sources += [ "platform/atk_util_auralinux_gtk.cc" ]
+ }
+
configs += [ "//build/config/linux/atk" ]
if (use_glib) {
--- a/build/config/linux/gtk/BUILD.gn
+++ b/build/config/linux/gtk/BUILD.gn
@@ -7,18 +7,10 @@ import("//build/config/linux/pkg_config.
assert(is_linux, "This file should only be referenced on Linux")
-# GN doesn't check visibility for configs so we give this an obviously internal
-# name to discourage random targets from accidentally depending on this and
-# bypassing the GTK target's visibility.
-pkg_config("gtk_internal_config") {
- # Gtk requires gmodule, but it does not list it as a dependency in some
- # misconfigured systems.
- packages = [
- "gmodule-2.0",
- "gtk+-${gtk_version}.0",
- "gthread-2.0",
- ]
-}
+# The target in this file will automatically reference GTK2 or GTK3 depending
+# on the state of the build flag. Some builds reference both 2 and 3, and some
+# builds reference neither, so both need to be available but in different
+# directories so pkg-config is only run when necessary.
# Basically no parts of Chrome should depend on GTK. To prevent accidents, the
# parts that explicitly need GTK are whitelisted on this target.
@@ -36,10 +28,13 @@ group("gtk") {
"//remoting/host:remoting_me2me_host_static",
"//remoting/test:it2me_standalone_host_main",
"//webrtc/examples:peerconnection_client",
- "//chrome/browser/ui/libgtkui:*",
]
- public_configs = [ ":gtk_internal_config" ]
+ if (gtk_version == 2) {
+ public_deps = [
+ "//build/config/linux/gtk2",
+ ]
+ }
}
# Depend on "gtkprint" to get this.
--- a/build/config/linux/gtk/gtk.gni
+++ b/build/config/linux/gtk/gtk.gni
@@ -7,4 +7,4 @@ declare_args() {
gtk_version = 3
}
-assert(gtk_version >= 3 && gtk_version <= 4)
+assert(gtk_version >= 2 && gtk_version <= 4)
--- /dev/null
+++ b/build/config/linux/gtk2/BUILD.gn
@@ -0,0 +1,33 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("//build/config/linux/pkg_config.gni")
+
+assert(is_linux, "This file should only be referenced on Linux")
+
+# Depend on //build/config/linux/gtk2 to use GTKv2. Depend on
+# //build/config/linux/gtk to get GTK 2 or 3 depending on the build flags.
+#
+# GN doesn't check visibility for configs so we give this an obviously internal
+# name to discourage random targets from accidentally depending on this and
+# bypassing the GTK target's visibility.
+pkg_config("gtk2_internal_config") {
+ # Gtk requires gmodule, but it does not list it as a dependency in some
+ # misconfigured systems.
+ packages = [
+ "gmodule-2.0",
+ "gtk+-2.0",
+ "gthread-2.0",
+ ]
+}
+
+# Basically no parts of Chrome should depend on GTK. To prevent accidents, the
+# parts that explicitly need GTK2 are whitelisted on this target.
+group("gtk2") {
+ visibility = [
+ "//build/config/linux/gtk",
+ "//chrome/browser/ui/libgtkui:*",
+ ]
+ public_configs = [ ":gtk2_internal_config" ]
+}
--- a/chrome/browser/ui/libgtkui/BUILD.gn
+++ b/chrome/browser/ui/libgtkui/BUILD.gn
@@ -9,120 +9,155 @@ import("//build/config/jumbo.gni")
import("//build/config/linux/gtk/gtk.gni")
import("//printing/buildflags/buildflags.gni")
-jumbo_component("libgtkui") {
- sources = [
- "app_indicator_icon.cc",
- "app_indicator_icon.h",
- "app_indicator_icon_menu.cc",
- "app_indicator_icon_menu.h",
- "gtk_background_painter.cc",
- "gtk_background_painter.h",
- "gtk_event_loop.cc",
- "gtk_event_loop.h",
- "gtk_key_bindings_handler.cc",
- "gtk_key_bindings_handler.h",
- "gtk_ui.cc",
- "gtk_ui.h",
- "gtk_util.cc",
- "gtk_util.h",
- "libgtkui_export.h",
- "menu_util.cc",
- "menu_util.h",
- "native_theme_gtk.cc",
- "native_theme_gtk.h",
- "nav_button_provider_gtk.cc",
- "nav_button_provider_gtk.h",
- "print_dialog_gtk.cc",
- "print_dialog_gtk.h",
- "printing_gtk_util.cc",
- "printing_gtk_util.h",
- "select_file_dialog_impl.cc",
- "select_file_dialog_impl.h",
- "select_file_dialog_impl_gtk.cc",
- "select_file_dialog_impl_gtk.h",
- "select_file_dialog_impl_kde.cc",
- "settings_provider.h",
- "settings_provider_gtk.cc",
- "settings_provider_gtk.h",
- "skia_utils_gtk.cc",
- "skia_utils_gtk.h",
- "unity_service.cc",
- "unity_service.h",
- "x11_input_method_context_impl_gtk.cc",
- "x11_input_method_context_impl_gtk.h",
- ]
-
- if (gtk_version <= 3) {
- sources += [
- "gtk_status_icon.cc",
- "gtk_status_icon.h",
+# Automatically depends on the GTK version associated with the current build
+# flags.
+group("libgtkui") {
+ if (gtk_version == 3) {
+ public_deps = [
+ ":libgtk3ui",
+ ]
+ } else {
+ public_deps = [
+ ":libgtk2ui",
]
}
+}
- configs += [
- "//build/config/linux/pangocairo",
- "//build/config/linux:x11",
- ]
-
- if (use_gio) {
- sources += [
- "settings_provider_gsettings.cc",
- "settings_provider_gsettings.h",
+template("libgtkui") {
+ component(target_name) {
+ sources = invoker.sources + [
+ "app_indicator_icon.cc",
+ "app_indicator_icon.h",
+ "app_indicator_icon_menu.cc",
+ "app_indicator_icon_menu.h",
+ "gtk_event_loop.cc",
+ "gtk_event_loop.h",
+ "gtk_key_bindings_handler.cc",
+ "gtk_key_bindings_handler.h",
+ "gtk_signal.h",
+ "gtk_status_icon.cc",
+ "gtk_status_icon.h",
+ "gtk_ui.cc",
+ "gtk_ui.h",
+ "gtk_util.cc",
+ "gtk_util.h",
+ "libgtkui_export.h",
+ "menu_util.cc",
+ "menu_util.h",
+ "settings_provider.h",
+ "print_dialog_gtk.cc",
+ "print_dialog_gtk.h",
+ "printing_gtk_util.cc",
+ "printing_gtk_util.h",
+ "select_file_dialog_impl.cc",
+ "select_file_dialog_impl.h",
+ "select_file_dialog_impl_gtk.cc",
+ "select_file_dialog_impl_gtk.h",
+ "select_file_dialog_impl_kde.cc",
+ "skia_utils_gtk.cc",
+ "skia_utils_gtk.h",
+ "unity_service.cc",
+ "unity_service.h",
+ "x11_input_method_context_impl_gtk.cc",
+ "x11_input_method_context_impl_gtk.h",
+ ]
+
+ configs += [
+ "//build/config/linux/pangocairo",
+ "//build/config/linux:x11",
]
- configs += [ "//build/linux:gio_config" ]
- }
- if (use_cups) {
- configs += [ "//printing:cups" ]
+ if (use_gio) {
+ sources += [
+ "settings_provider_gsettings.cc",
+ "settings_provider_gsettings.h",
+ ]
+ configs += [ "//build/linux:gio_config" ]
+ }
+
+ if (use_cups) {
+ configs += [ "//printing:cups" ]
+ }
+
+ defines = [ "LIBGTKUI_IMPLEMENTATION" ]
+
+ deps = invoker.deps + [
+ "//chrome/browser/ui/views",
+ "//chrome/common:constants",
+ "//base",
+ "//base:i18n",
+ "//base/third_party/dynamic_annotations",
+ "//cc/paint",
+ "//chrome/common:buildflags",
+ "//chrome:extra_resources",
+ "//chrome:resources",
+ "//chrome:strings",
+ "//chrome/app:command_ids",
+ "//chrome/app/theme:theme_resources",
+ "//components/prefs",
+ "//components/resources",
+ "//content/public/browser",
+ "//printing",
+ "//skia",
+
+ # GTK pulls pangoft2, which requires HarfBuzz symbols. When linking
+ # our own HarfBuzz avoid mixing symbols from system HarfBuzz and
+ # our own through the indirect dependency to harfbuzz-ng here.
+ "//third_party:freetype_harfbuzz",
+ "//ui/aura",
+ "//ui/base",
+ "//ui/base/ime",
+ "//ui/base/ime/linux",
+ "//ui/display",
+ "//ui/events",
+ "//ui/events:dom_keyboard_layout",
+ "//ui/events:dom_keycode_converter",
+ "//ui/events:events_base",
+ "//ui/events/platform/x11",
+ "//ui/gfx",
+ "//ui/gfx/geometry",
+ "//ui/gfx/x",
+ "//ui/native_theme",
+ "//ui/resources",
+ "//ui/shell_dialogs",
+ "//ui/strings",
+ "//ui/views",
+ ]
+ public_deps = [
+ "//chrome/browser:theme_properties",
+ ]
}
+}
- defines = [ "LIBGTKUI_IMPLEMENTATION" ]
-
- deps = [
- "//base",
- "//base:i18n",
- "//base/third_party/dynamic_annotations",
- "//build/config/linux/gtk",
- "//build/config/linux/gtk:gtkprint",
- "//cc/paint",
- "//chrome:extra_resources",
- "//chrome:resources",
- "//chrome:strings",
- "//chrome/app:command_ids",
- "//chrome/app/theme:theme_resources",
- "//chrome/browser/ui/views",
- "//chrome/common:buildflags",
- "//chrome/common:constants",
- "//components/prefs",
- "//components/resources",
- "//content/public/browser",
- "//printing",
- "//skia",
-
- # GTK pulls pangoft2, which requires HarfBuzz symbols. When linking
- # our own HarfBuzz avoid mixing symbols from system HarfBuzz and
- # our own through the indirect dependency to harfbuzz-ng here.
- "//third_party:freetype_harfbuzz",
- "//ui/aura",
- "//ui/base",
- "//ui/base/ime",
- "//ui/base/ime/linux",
- "//ui/display",
- "//ui/events",
- "//ui/events:dom_keyboard_layout",
- "//ui/events:dom_keycode_converter",
- "//ui/events:events_base",
- "//ui/events/platform/x11",
- "//ui/gfx",
- "//ui/gfx/geometry",
- "//ui/gfx/x",
- "//ui/native_theme",
- "//ui/resources",
- "//ui/shell_dialogs",
- "//ui/strings",
- "//ui/views",
- ]
- public_deps = [
- "//chrome/browser:theme_properties",
- ]
+if (gtk_version == 3) {
+ libgtkui("libgtk3ui") {
+ sources = [
+ "gtk_background_painter.cc",
+ "gtk_background_painter.h",
+ "native_theme_gtk.cc",
+ "native_theme_gtk.h",
+ "nav_button_provider_gtk.cc",
+ "nav_button_provider_gtk.h",
+ "settings_provider_gtk.cc",
+ "settings_provider_gtk.h",
+ ]
+ deps = [
+ "//build/config/linux/gtk:gtkprint",
+ ]
+ }
+} else {
+ libgtkui("libgtk2ui") {
+ sources = [
+ "gtk2/chrome_gtk_menu_subclasses.cc",
+ "gtk2/chrome_gtk_menu_subclasses.h",
+ "gtk2/chrome_gtk_frame.cc",
+ "gtk2/chrome_gtk_frame.h",
+ "gtk2/native_theme_gtk2.cc",
+ "gtk2/native_theme_gtk2.h",
+ ]
+ deps = [
+ "//build/config/linux/gtk2",
+ "//build/config/linux/gtk:gtkprint",
+ ]
+ }
}
--- a/chrome/browser/ui/libgtkui/gtk_key_bindings_handler.cc
+++ b/chrome/browser/ui/libgtkui/gtk_key_bindings_handler.cc
@@ -77,7 +77,11 @@ bool GtkKeyBindingsHandler::MatchEvent(
// will be emitted.
gtk_bindings_activate_event(
+#if GDK_MAJOR_VERSION >= 3
G_OBJECT(handler_),
+#else
+ GTK_OBJECT(handler_),
+#endif
&gdk_event);
bool matched = !edit_commands_.empty();
--- a/chrome/browser/ui/libgtkui/gtk_status_icon.cc
+++ b/chrome/browser/ui/libgtkui/gtk_status_icon.cc
@@ -21,11 +21,13 @@ GtkStatusIcon::GtkStatusIcon(const gfx::
const base::string16& tool_tip) {
GdkPixbuf* pixbuf = GdkPixbufFromSkBitmap(*image.bitmap());
{
+#if GTK_MAJOR_VERSION == 3
// GTK has a bug that leaks 384 bytes when creating a GtkStatusIcon. It
// will not be fixed since the status icon was deprecated in version 3.14.
// Luckily, Chromium doesn't need to create a status icon very often, if at
// all.
ANNOTATE_SCOPED_MEMORY_LEAK;
+#endif
gtk_status_icon_ = gtk_status_icon_new_from_pixbuf(pixbuf);
}
g_object_unref(pixbuf);
--- a/chrome/browser/ui/libgtkui/gtk_ui.cc
+++ b/chrome/browser/ui/libgtkui/gtk_ui.cc
@@ -72,6 +72,15 @@
#include "ui/views/linux_ui/window_button_order_observer.h"
#include "ui/views/resources/grit/views_resources.h"
+#if GTK_MAJOR_VERSION == 2
+#include "chrome/browser/ui/libgtkui/gtk2/chrome_gtk_frame.h"
+#include "chrome/browser/ui/libgtkui/gtk2/native_theme_gtk2.h"
+#elif GTK_MAJOR_VERSION == 3
+#include "chrome/browser/ui/libgtkui/native_theme_gtk.h"
+#include "chrome/browser/ui/libgtkui/nav_button_provider_gtk.h"
+#include "chrome/browser/ui/libgtkui/settings_provider_gtk.h"
+#endif
+
#if defined(USE_GIO)
#include "chrome/browser/ui/libgtkui/settings_provider_gsettings.h"
#endif
@@ -131,6 +140,49 @@ class GtkButtonImageSource : public gfx:
width, height, width * 4);
cairo_t* cr = cairo_create(surface);
+#if GTK_MAJOR_VERSION == 2
+ // Create a temporary GTK button to snapshot
+ GtkWidget* window = gtk_offscreen_window_new();
+ GtkWidget* button = gtk_toggle_button_new();
+
+ if (state_ == ui::NativeTheme::kPressed)
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), true);
+ else if (state_ == ui::NativeTheme::kDisabled)
+ gtk_widget_set_sensitive(button, false);
+
+ gtk_widget_set_size_request(button, width, height);
+ gtk_container_add(GTK_CONTAINER(window), button);
+
+ if (is_blue_)
+ TurnButtonBlue(button);
+
+ gtk_widget_show_all(window);
+
+ if (focus_)
+ GTK_WIDGET_SET_FLAGS(button, GTK_HAS_FOCUS);
+
+ int w, h;
+ GdkPixmap* pixmap;
+
+ {
+ // http://crbug.com/346740
+ ANNOTATE_SCOPED_MEMORY_LEAK;
+ pixmap = gtk_widget_get_snapshot(button, nullptr);
+ }
+
+ gdk_drawable_get_size(GDK_DRAWABLE(pixmap), &w, &h);
+ GdkColormap* colormap = gdk_drawable_get_colormap(pixmap);
+ GdkPixbuf* pixbuf = gdk_pixbuf_get_from_drawable(
+ nullptr, GDK_DRAWABLE(pixmap), colormap, 0, 0, 0, 0, w, h);
+
+ gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
+ cairo_paint(cr);
+
+ g_object_unref(pixbuf);
+ g_object_unref(pixmap);
+
+ gtk_widget_destroy(window);
+#else
ScopedStyleContext context = GetStyleContextFromCss(
is_blue_ ? "GtkButton#button.default.suggested-action"
: "GtkButton#button");
@@ -178,6 +230,7 @@ class GtkButtonImageSource : public gfx:
gtk_render_focus(context, cr, focus_rect.x(), focus_rect.y(),
focus_rect.width(), focus_rect.height());
}
+#endif
cairo_destroy(cr);
cairo_surface_destroy(surface);
@@ -237,15 +290,19 @@ int indicators_count;
// The unknown content type.
const char kUnknownContentType[] = "application/octet-stream";
+#if GTK_MAJOR_VERSION > 2
using GdkSetAllowedBackendsFn = void (*)(const gchar*);
// Place this function pointer in read-only memory after being resolved to
// prevent it being tampered with. See https://crbug.com/771365 for details.
PROTECTED_MEMORY_SECTION base::ProtectedMemory<GdkSetAllowedBackendsFn>
g_gdk_set_allowed_backends;
+#endif
std::unique_ptr<SettingsProvider> CreateSettingsProvider(GtkUi* gtk_ui) {
+#if GTK_MAJOR_VERSION == 3
if (GtkVersionCheck(3, 14))
return std::make_unique<SettingsProviderGtk>(gtk_ui);
+#endif
#if defined(USE_GIO)
return std::make_unique<SettingsProviderGSettings>(gtk_ui);
#else
@@ -303,8 +360,10 @@ gfx::FontRenderParams GetGtkFontRenderPa
}
views::LinuxUI::WindowFrameAction GetDefaultMiddleClickAction() {
+#if GTK_MAJOR_VERSION == 3
if (GtkVersionCheck(3, 14))
return views::LinuxUI::WindowFrameAction::kNone;
+#endif
std::unique_ptr<base::Environment> env(base::Environment::Create());
switch (base::nix::GetDesktopEnvironment(env.get())) {
case base::nix::DESKTOP_ENVIRONMENT_KDE4:
@@ -329,6 +388,7 @@ GtkUi::GtkUi() {
{ActionSource::kMiddleClick, GetDefaultMiddleClickAction()},
{ActionSource::kRightClick, Action::kMenu}};
+#if GTK_MAJOR_VERSION >= 3
// Force Gtk to use Xwayland if it would have used wayland. libgtkui assumes
// the use of X11 (eg. X11InputMethodContextImplGtk) and will crash under
// other backends.
@@ -345,9 +405,17 @@ GtkUi::GtkUi() {
// do it once it is ready.
std::unique_ptr<base::Environment> env(base::Environment::Create());
env->SetVar("NO_AT_BRIDGE", "1");
+#endif
GtkInitFromCommandLine(*base::CommandLine::ForCurrentProcess());
+#if GTK_MAJOR_VERSION == 2
+ native_theme_ = NativeThemeGtk2::instance();
+ fake_window_ = chrome_gtk_frame_new();
+#elif GTK_MAJOR_VERSION == 3
native_theme_ = NativeThemeGtk::instance();
fake_window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+#else
+#error "Unsupported GTK version"
+#endif
gtk_widget_realize(fake_window_);
}
@@ -731,8 +799,10 @@ bool GtkUi::PreferDarkTheme() const {
#if BUILDFLAG(ENABLE_NATIVE_WINDOW_NAV_BUTTONS)
std::unique_ptr<views::NavButtonProvider> GtkUi::CreateNavButtonProvider() {
+#if GTK_MAJOR_VERSION == 3
if (GtkVersionCheck(3, 14))
return std::make_unique<libgtkui::NavButtonProviderGtk>();
+#endif
return nullptr;
}
#endif
@@ -818,6 +888,69 @@ void GtkUi::LoadGtkValues() {
}
void GtkUi::UpdateColors() {
+#if GTK_MAJOR_VERSION == 2
+
+ const color_utils::HSL kDefaultFrameShift = {-1, -1, 0.4};
+ SkColor frame_color =
+ native_theme_->GetSystemColor(ui::NativeTheme::kColorId_WindowBackground);
+ frame_color = color_utils::HSLShift(frame_color, kDefaultFrameShift);
+ GetChromeStyleColor("frame-color", &frame_color);
+ colors_[ThemeProperties::COLOR_FRAME] = frame_color;
+
+ GtkStyle* style = gtk_rc_get_style(fake_window_);
+ SkColor temp_color = color_utils::HSLShift(
+ GdkColorToSkColor(style->bg[GTK_STATE_INSENSITIVE]), kDefaultFrameShift);
+ GetChromeStyleColor("inactive-frame-color", &temp_color);
+ colors_[ThemeProperties::COLOR_FRAME_INACTIVE] = temp_color;
+
+ temp_color = color_utils::HSLShift(frame_color, kDefaultTintFrameIncognito);
+ GetChromeStyleColor("incognito-frame-color", &temp_color);
+ colors_[ThemeProperties::COLOR_FRAME_INCOGNITO] = temp_color;
+
+ SkColor tab_color =
+ native_theme_->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground);
+ SkColor label_color = native_theme_->GetSystemColor(
+ ui::NativeTheme::kColorId_LabelEnabledColor);
+
+ colors_[ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON] =
+ color_utils::DeriveDefaultIconColor(label_color);
+
+ colors_[ThemeProperties::COLOR_TAB_TEXT] = label_color;
+ colors_[ThemeProperties::COLOR_BOOKMARK_TEXT] = label_color;
+ colors_[ThemeProperties::COLOR_BACKGROUND_TAB_TEXT] =
+ color_utils::BlendTowardMaxContrast(label_color, 50);
+
+ inactive_selection_bg_color_ = native_theme_->GetSystemColor(
+ ui::NativeTheme::kColorId_TextfieldReadOnlyBackground);
+ inactive_selection_fg_color_ = native_theme_->GetSystemColor(
+ ui::NativeTheme::kColorId_TextfieldReadOnlyColor);
+
+ // We pick the text and background colors for the NTP out of the
+ // colors for a GtkEntry. We do this because GtkEntries background
+ // color is never the same as |tab_color|, is usually a white,
+ // and when it isn't a white, provides sufficient contrast to
+ // |tab_color|. Try this out with Darklooks, HighContrastInverse
+ // or ThinIce.
+ colors_[ThemeProperties::COLOR_NTP_BACKGROUND] =
+ native_theme_->GetSystemColor(
+ ui::NativeTheme::kColorId_TextfieldDefaultBackground);
+ colors_[ThemeProperties::COLOR_NTP_TEXT] = native_theme_->GetSystemColor(
+ ui::NativeTheme::kColorId_TextfieldDefaultColor);
+ // The NTP header is the color that surrounds the current active
+ // thumbnail on the NTP, and acts as the border of the "Recent
+ // Links" box. It would be awesome if they were separated so we
+ // could use GetBorderColor() for the border around the "Recent
+ // Links" section, but matching the frame color is more important.
+ colors_[ThemeProperties::COLOR_NTP_HEADER] =
+ colors_[ThemeProperties::COLOR_FRAME];
+
+ colors_[ThemeProperties::COLOR_TOOLBAR] = tab_color;
+ colors_[ThemeProperties::COLOR_DOWNLOAD_SHELF] = tab_color;
+ colors_[ThemeProperties::COLOR_INFOBAR] = tab_color;
+ colors_[ThemeProperties::COLOR_STATUS_BUBBLE] = tab_color;
+
+#else
+
SkColor location_bar_border = GetBorderColor("GtkEntry#entry");
if (SkColorGetA(location_bar_border))
colors_[ThemeProperties::COLOR_LOCATION_BAR_BORDER] = location_bar_border;
@@ -857,6 +990,8 @@ void GtkUi::UpdateColors() {
colors_[ThemeProperties::COLOR_BACKGROUND_TAB_INCOGNITO_INACTIVE] =
SK_ColorTRANSPARENT;
+#endif
+
colors_[ThemeProperties::COLOR_NTP_LINK] = native_theme_->GetSystemColor(
ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused);
@@ -878,6 +1013,8 @@ void GtkUi::UpdateColors() {
native_theme_->GetSystemColor(
ui::NativeTheme::kColorId_ThrobberWaitingColor);
+#if GTK_MAJOR_VERSION >= 3
+
// Generate colors that depend on whether or not a custom window frame is
// used. These colors belong in |color_map| below, not |colors_|.
for (bool custom_frame : {false, true}) {
@@ -970,6 +1107,8 @@ void GtkUi::UpdateColors() {
toolbar_top_separator_inactive;
}
}
+
+#endif
}
void GtkUi::UpdateCursorTheme() {
@@ -1034,6 +1173,20 @@ void GtkUi::UpdateDefaultFont() {
g_object_unref(fake_label);
}
+bool GtkUi::GetChromeStyleColor(const char* style_property,
+ SkColor* ret_color) const {
+#if GTK_MAJOR_VERSION == 2
+ GdkColor* style_color = nullptr;
+ gtk_widget_style_get(fake_window_, style_property, &style_color, nullptr);
+ if (style_color) {
+ *ret_color = GdkColorToSkColor(*style_color);
+ gdk_color_free(style_color);
+ return true;
+ }
+#endif
+ return false;
+}
+
void GtkUi::ResetStyle() {
colors_.clear();
custom_frame_colors_.clear();
@@ -1046,12 +1199,19 @@ float GtkUi::GetRawDeviceScaleFactor() {
if (display::Display::HasForceDeviceScaleFactor())
return display::Display::GetForcedDeviceScaleFactor();
+#if GTK_MAJOR_VERSION == 2
+ GtkSettings* gtk_settings = gtk_settings_get_default();
+ gint gtk_dpi = -1;
+ g_object_get(gtk_settings, "gtk-xft-dpi", >k_dpi, nullptr);
+ const float scale_factor = gtk_dpi / (1024 * kDefaultDPI);
+#else
GdkScreen* screen = gdk_screen_get_default();
gint scale = gtk_widget_get_scale_factor(fake_window_);
DCHECK_GT(scale, 0);
gdouble resolution = gdk_screen_get_resolution(screen);
const float scale_factor =
resolution <= 0 ? scale : resolution * scale / kDefaultDPI;
+#endif
// Blacklist scaling factors <120% (crbug.com/484400) and round
// to 1 decimal to prevent rendering problems (crbug.com/485183).
--- a/chrome/browser/ui/libgtkui/gtk_ui.h
+++ b/chrome/browser/ui/libgtkui/gtk_ui.h
@@ -138,6 +138,10 @@ class GtkUi : public views::LinuxUI {
// Updates |default_font_*|.
void UpdateDefaultFont();
+ // Gets a ChromeGtkFrame theme color; returns true on success.
+ bool GetChromeStyleColor(const char* sytle_property,
+ SkColor* ret_color) const;
+
float GetRawDeviceScaleFactor();
ui::NativeTheme* native_theme_;
--- a/chrome/browser/ui/libgtkui/gtk_util.cc
+++ b/chrome/browser/ui/libgtkui/gtk_util.cc
@@ -122,8 +122,12 @@ int EventFlagsFromGdkState(guint state)
}
void TurnButtonBlue(GtkWidget* button) {
+#if GTK_MAJOR_VERSION == 2
+ gtk_widget_set_can_default(button, true);
+#else
gtk_style_context_add_class(gtk_widget_get_style_context(button),
"suggested-action");
+#endif
}
void SetGtkTransientForAura(GtkWidget* dialog, aura::Window* parent) {
@@ -181,6 +185,7 @@ void ParseButtonLayout(const std::string
}
}
+#if GTK_MAJOR_VERSION > 2
namespace {
float GetDeviceScaleFactor() {
@@ -588,6 +593,7 @@ SkColor GetSeparatorColor(const std::str
gtk_render_frame(context, surface.cairo(), 0, 0, w, h);
return surface.GetAveragePixelValue(false);
}
+#endif
std::string GetGtkSettingsStringProperty(GtkSettings* settings,
const gchar* prop_name) {
--- a/chrome/browser/ui/libgtkui/gtk_util.h
+++ b/chrome/browser/ui/libgtkui/gtk_util.h
@@ -67,6 +67,7 @@ void ParseButtonLayout(const std::string
std::vector<views::FrameButton>* leading_buttons,
std::vector<views::FrameButton>* trailing_buttons);
+#if GTK_MAJOR_VERSION > 2
void* GetGdkSharedLibrary();
void* GetGtkSharedLibrary();
@@ -183,6 +184,7 @@ SkColor GetSelectionBgColor(const std::s
// Get the color of the GtkSeparator specified by |css_selector|.
SkColor GetSeparatorColor(const std::string& css_selector);
+#endif
// Get a GtkSettings property as a C++ string.
std::string GetGtkSettingsStringProperty(GtkSettings* settings,
--- a/chrome/browser/ui/libgtkui/print_dialog_gtk.cc
+++ b/chrome/browser/ui/libgtkui/print_dialog_gtk.cc
@@ -290,8 +290,14 @@ void PrintDialogGtk::UpdateSettings(prin
gtk_page_setup_set_paper_size(page_setup_, custom_size);
gtk_paper_size_free(custom_size);
}
+#if GTK_CHECK_VERSION(2, 28, 0)
g_list_free_full(gtk_paper_sizes,
reinterpret_cast<GDestroyNotify>(gtk_paper_size_free));
+#else
+ g_list_foreach(gtk_paper_sizes,
+ reinterpret_cast<GFunc>(gtk_paper_size_free), nullptr);
+ g_list_free(gtk_paper_sizes);
+#endif
}
} else {
VLOG(1) << "Using default paper size";
@@ -479,7 +485,11 @@ void PrintDialogGtk::OnResponse(GtkWidge
static void OnJobCompletedThunk(GtkPrintJob* print_job,
gpointer user_data,
+#if GTK_MAJOR_VERSION == 2
+ GError* error
+#else
const GError* error
+#endif
) {
static_cast<PrintDialogGtk*>(user_data)->OnJobCompleted(print_job, error);
}
--- a/chrome/browser/ui/libgtkui/x11_input_method_context_impl_gtk.cc
+++ b/chrome/browser/ui/libgtkui/x11_input_method_context_impl_gtk.cc
@@ -88,7 +88,12 @@ bool X11InputMethodContextImplGtk::Dispa
gint win_y = 0;
gdk_window_get_origin(event->key.window, &win_x, &win_y);
+#if GTK_MAJOR_VERSION == 2
+ gint factor = 1;
+#else
gint factor = gdk_window_get_scale_factor(event->key.window);
+#endif
+
gint caret_x = last_caret_bounds_.x() / factor;
gint caret_y = last_caret_bounds_.y() / factor;
gint caret_w = last_caret_bounds_.width() / factor;
@@ -233,11 +238,19 @@ GdkEvent* X11InputMethodContextImplGtk::
g_free(keyvals);
keyvals = nullptr;
// Get a GdkWindow.
+#if GTK_CHECK_VERSION(2, 24, 0)
GdkWindow* window = gdk_x11_window_lookup_for_display(display, xkey.window);
+#else
+ GdkWindow* window = gdk_window_lookup_for_display(display, xkey.window);
+#endif
if (window)
g_object_ref(window);
else
+#if GTK_CHECK_VERSION(2, 24, 0)
window = gdk_x11_window_foreign_new_for_display(display, xkey.window);
+#else
+ window = gdk_window_foreign_new_for_display(display, xkey.window);
+#endif
if (!window) {
LOG(ERROR) << "Cannot get a GdkWindow for a key event.";
return nullptr;
--- /dev/null
+++ b/chrome/browser/ui/libgtkui/gtk2/chrome_gtk_frame.cc
@@ -0,0 +1,154 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/libgtkui/gtk2/chrome_gtk_frame.h"
+
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+
+G_BEGIN_DECLS
+
+// MetaFrames declaration
+G_DEFINE_TYPE(MetaFrames, meta_frames, GTK_TYPE_WINDOW)
+
+static void meta_frames_class_init(MetaFramesClass* frames_class) {
+ // Noop since we don't declare anything.
+}
+
+static void meta_frames_init(MetaFrames* button) {
+}
+
+
+// ChromeGtkFrame declaration
+G_DEFINE_TYPE(ChromeGtkFrame, chrome_gtk_frame, meta_frames_get_type())
+
+static void chrome_gtk_frame_class_init(ChromeGtkFrameClass* frame_class) {
+ GtkWidgetClass* widget_class = reinterpret_cast<GtkWidgetClass*>(frame_class);
+
+ // Frame tints:
+ gtk_widget_class_install_style_property(
+ widget_class,
+ g_param_spec_boxed(
+ "frame-color",
+ "Frame Color",
+ "The color that the chrome frame will be. (If unspecified, "
+ " Chrome will take ChromeGtkFrame::bg[SELECTED] and slightly darken"
+ " it.)",
+ GDK_TYPE_COLOR,
+ G_PARAM_READABLE));
+ gtk_widget_class_install_style_property(
+ widget_class,
+ g_param_spec_boxed(
+ "inactive-frame-color",
+ "Inactive Frame Color",
+ "The color that the inactive chrome frame will be. (If"
+ " unspecified, Chrome will take ChromeGtkFrame::bg[INSENSITIVE]"
+ " and slightly darken it.)",
+ GDK_TYPE_COLOR,
+ G_PARAM_READABLE));
+ gtk_widget_class_install_style_property(
+ widget_class,
+ g_param_spec_boxed(
+ "incognito-frame-color",
+ "Incognito Frame Color",
+ "The color that the incognito frame will be. (If unspecified,"
+ " Chrome will take the frame color and tint it by Chrome's default"
+ " incognito tint.)",
+ GDK_TYPE_COLOR,
+ G_PARAM_READABLE));
+ gtk_widget_class_install_style_property(
+ widget_class,
+ g_param_spec_boxed(
+ "incognito-inactive-frame-color",
+ "Incognito Inactive Frame Color",
+ "The color that the inactive incognito frame will be. (If"
+ " unspecified, Chrome will take the frame color and tint it by"
+ " Chrome's default incognito tint.)",
+ GDK_TYPE_COLOR,
+ G_PARAM_READABLE));
+
+ // Frame gradient control:
+ gtk_widget_class_install_style_property(
+ widget_class,
+ g_param_spec_int(
+ "frame-gradient-size",
+ "Chrome Frame Gradient Size",
+ "The size of the gradient on top of the frame image. Specify 0 to"
+ " make the frame a solid color.",
+ 0, // 0 disables the gradient
+ 128, // The frame image is only up to 128 pixels tall.
+ 16, // By default, gradients are 16 pixels high.
+ G_PARAM_READABLE));
+ gtk_widget_class_install_style_property(
+ widget_class,
+ g_param_spec_boxed(
+ "frame-gradient-color",
+ "Frame Gradient Color",
+ "The top color of the chrome frame gradient. (If unspecified,"
+ " chrome will create a lighter tint of frame-color",
+ GDK_TYPE_COLOR,
+ G_PARAM_READABLE));
+ gtk_widget_class_install_style_property(
+ widget_class,
+ g_param_spec_boxed(
+ "inactive-frame-gradient-color",
+ "Inactive Frame Gradient Color",
+ "The top color of the inactive chrome frame gradient. (If"
+ " unspecified, chrome will create a lighter tint of frame-color",
+ GDK_TYPE_COLOR,
+ G_PARAM_READABLE));
+ gtk_widget_class_install_style_property(
+ widget_class,
+ g_param_spec_boxed(
+ "incognito-frame-gradient-color",
+ "Incognito Frame Gradient Color",
+ "The top color of the incognito chrome frame gradient. (If"
+ " unspecified, chrome will create a lighter tint of frame-color",
+ GDK_TYPE_COLOR,
+ G_PARAM_READABLE));
+ gtk_widget_class_install_style_property(
+ widget_class,
+ g_param_spec_boxed(
+ "incognito-inactive-frame-gradient-color",
+ "Incognito Inactive Frame Gradient Color",
+ "The top color of the incognito inactive chrome frame gradient. (If"
+ " unspecified, chrome will create a lighter tint of frame-color",
+ GDK_TYPE_COLOR,
+ G_PARAM_READABLE));
+
+ // Scrollbar color properties:
+ gtk_widget_class_install_style_property(
+ widget_class,
+ g_param_spec_boxed(
+ "scrollbar-slider-prelight-color",
+ "Scrollbar Slider Prelight Color",
+ "The color applied to the mouse is above the tab",
+ GDK_TYPE_COLOR,
+ G_PARAM_READABLE));
+ gtk_widget_class_install_style_property(
+ widget_class,
+ g_param_spec_boxed(
+ "scrollbar-slider-normal-color",
+ "Scrollbar Slider Normal Color",
+ "The color applied to the slider normally",
+ GDK_TYPE_COLOR,
+ G_PARAM_READABLE));