diff --git a/BUILD.gn b/BUILD.gn index d80fb6676..ad4ca86be 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1478,6 +1478,20 @@ action("make_config_header") { args = rebase_path(outputs + [ "$root_out_dir/args.gn" ], root_build_dir) } +# Generate cef_color_ids.h. +action("make_colorids_header") { + script = "tools/make_colorids_header.py" + + inputs = [ + "//ui/color/color_id.h", + "//components/color/color_id.h", + "//chrome/browser/ui/color/chrome_color_id.h", + ] + outputs = [ "$root_out_dir/includes/include/cef_color_ids.h" ] + + args = rebase_path(outputs + inputs, root_build_dir) +} + # Generate pack files and associated CEF header files. group("cef_make_headers") { deps = [ @@ -1486,6 +1500,7 @@ group("cef_make_headers") { ":make_pack_header_command_ids", ":make_api_hash_header", ":make_config_header", + ":make_colorids_header", ] } diff --git a/include/base/internal/cef_color_id_macros.inc b/include/base/internal/cef_color_id_macros.inc new file mode 100644 index 000000000..4522726fa --- /dev/null +++ b/include/base/internal/cef_color_id_macros.inc @@ -0,0 +1,8 @@ +// Copyright (c) 2024 The Chromium Embedded Framework 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 color id macros from the Chromium source location. When creating a +// CEF binary distribution this file will be replaced with the Chromium version. + +#include "ui/color/color_id_macros.inc" diff --git a/libcef/browser/views/view_util.cc b/libcef/browser/views/view_util.cc index b7c5c1482..f4438c6f3 100644 --- a/libcef/browser/views/view_util.cc +++ b/libcef/browser/views/view_util.cc @@ -6,8 +6,10 @@ #include +#include "include/cef_color_ids.h" #include "libcef/browser/views/view_adapter.h" +#include "chrome/browser/ui/color/chrome_color_id.h" #include "ui/color/color_provider.h" #include "ui/color/color_provider_manager.h" #include "ui/display/display.h" @@ -342,6 +344,11 @@ bool ConvertPointFromWindow(views::View* view, gfx::Point* point) { } SkColor GetColor(views::View* view, ui::ColorId id) { + // Verify that our enum matches Chromium's values. + static_assert(static_cast(CEF_ChromeColorsEnd) == + static_cast(kChromeColorsEnd), + "enum mismatch"); + // |color_provider| will be nullptr if |view| has not yet been added to a // Widget. if (auto color_provider = view->GetColorProvider()) { diff --git a/tools/distrib/transfer.cfg b/tools/distrib/transfer.cfg index d3a65eaf7..2ca3736e0 100644 --- a/tools/distrib/transfer.cfg +++ b/tools/distrib/transfer.cfg @@ -14,4 +14,8 @@ 'source' : '../net/base/net_error_list.h', 'target' : 'include/base/internal/cef_net_error_list.h', }, + { + 'source' : '../ui/color/color_id_macros.inc', + 'target' : 'include/base/internal/cef_color_id_macros.inc', + }, ] diff --git a/tools/make_capi_header.py b/tools/make_capi_header.py index 6f11286d0..5e270d0be 100644 --- a/tools/make_capi_header.py +++ b/tools/make_capi_header.py @@ -4,7 +4,6 @@ from __future__ import absolute_import from cef_parser import * -from date_util import * def make_capi_global_funcs(funcs, defined_names, translate_map, indent): @@ -47,36 +46,8 @@ def make_capi_header(header, filename): translate_map = header.get_capi_translations() # header string - result = \ -"""// Copyright (c) $YEAR$ Marshall A. Greenblatt. All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the name Chromium Embedded -// Framework nor the names of its contributors may be used to endorse -// or promote products derived from this software without specific prior -// written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// + result = get_copyright(full=True, translator=False) + \ +"""// // --------------------------------------------------------------------------- // // This file was generated by the CEF translator tool and should not edited @@ -193,8 +164,6 @@ extern "C" { #endif // $GUARD$ """ - # add the copyright year - result = result.replace('$YEAR$', get_year()) # add the guard string guard = 'CEF_INCLUDE_CAPI_' + \ filename.replace('/', '_').replace('.', '_capi_').upper() + '_' diff --git a/tools/make_colorids_header.py b/tools/make_colorids_header.py new file mode 100644 index 000000000..12763e698 --- /dev/null +++ b/tools/make_colorids_header.py @@ -0,0 +1,167 @@ +#!/usr/bin/env python +# Copyright (c) 2024 The Chromium Embedded Framework Authors. All rights +# reserved. Use of this source code is governed by a BSD-style license +# that can be found in the LICENSE file. +""" +A simple utility function to merge color enum files into a single enum file. +""" + +from __future__ import absolute_import +from __future__ import print_function +from cef_parser import get_copyright +from file_util import * +import os +import re +import string +import sys + + +def MakeFileSegment(input): + result = """ + +// --------------------------------------------------------------------------- +// From $FILE$: + +""" + + result = result.replace('$FILE$', input.replace('../../', '')) + + contents = read_file(input) + + # Extract the portion that defines the enum values. + start_str = "\n// clang-format off" + start_pos = contents.find(start_str) + assert start_pos > 0, input + end_pos1 = contents.find("\n#include", start_pos) + end_pos2 = contents.find("\n// clang-format on", start_pos) + end_pos = min(end_pos1, end_pos2) + assert end_pos > start_pos, input + + extract = contents[start_pos + len(start_str):end_pos].strip() + + return result + extract + + +def MakeFile(output, input): + # Header string. + result = get_copyright(full=True, translator=False) + \ +"""// +// --------------------------------------------------------------------------- +// +// This file is generated by the make_colorids_header.py tool. +// + +#ifndef $GUARD$ +#define $GUARD$ +#pragma once + +#include "include/base/cef_build.h" +""" + + # Generate the file segments. + segments = '' + for file in input: + segments += MakeFileSegment(file) + + # Extract the unique names of all defines. + p = re.compile('#define\s([A-Za-z0-9_]{1,})\s') + all_defines = sorted(set(p.findall(segments))) + + undefines = "\n".join(["#undef %s" % define for define in all_defines]) + + # Undefine all defines that will be used in this header. + contents = """ +// Undefine the macros that will be defined in this file. +// This avoids previous definition conflicts with Chromium. +""" + undefines + segments + """ + +#include "include/base/internal/cef_color_id_macros.inc" + +#ifdef __cplusplus +extern "C" { +#endif + +/// +/// All input, intermediary, and output colors known to CEF/Chromium. +/// Clients can optionally extend this enum with additional values. +/// Clients define enum values from kChromeColorsEnd. Values named +/// beginning with "kColor" represent the actual colors; the rest are +/// markers. +/// +typedef enum { + kUiColorsStart = 0, + + COLOR_IDS + + kUiColorsEnd, + + kComponentsColorsStart = kUiColorsEnd, + + COMPONENTS_COLOR_IDS + + kComponentsColorsEnd, + + kChromeColorsStart = kComponentsColorsEnd, + + CHROME_COLOR_IDS + + // Clients must start custom color IDs from this value. + kChromeColorsEnd, + + // Clients must not assign IDs larger than this value. This is used to + // verify that color IDs and color set IDs are not interchanged. + kUiColorsLast = 0xffff +} cef_color_id_t; + +#ifdef __cplusplus +} +#endif + +// Note that this second include is not redundant. The second inclusion of the +// .inc file serves to undefine the macros the first inclusion defined. +#include "include/base/internal/cef_color_id_macros.inc" + +// Undefine the macros that were defined in this file. +""" + + # Undefine all defines that were used in this header. + contents += undefines + + replacements = ( + # Update platform defines. + ('BUILDFLAG(IS_', 'defined(OS_'), + ('defined(USE_AURA)', '!defined(OS_MAC)'), + # Update enum value style. + ('kColor', 'CEF_Color'), + ('kUiColors', 'CEF_UiColors'), + ('kComponentsColors', 'CEF_ComponentsColors'), + ('kChromeColors', 'CEF_ChromeColors')) + for find, replace in replacements: + contents = contents.replace(find, replace) + + result += contents + + # Add footer string. + result += """ + +#endif // $GUARD$ +""" + + # Add the guard string. + filename = os.path.split(output)[1] + guard = 'CEF_INCLUDE_' + filename.replace('.', '_').upper() + '_' + result = result.replace('$GUARD$', guard) + + write_file_if_changed(output, result) + + +def main(argv): + if len(argv) < 3: + print(("Usage:\n %s [input_file2] ... " % + argv[0])) + sys.exit(-1) + MakeFile(argv[1], argv[2:]) + + +if '__main__' == __name__: + main(sys.argv) diff --git a/tools/make_distrib.py b/tools/make_distrib.py index 239752527..0de6e5193 100644 --- a/tools/make_distrib.py +++ b/tools/make_distrib.py @@ -732,6 +732,7 @@ if mode == 'standard' or mode == 'minimal': # Transfer generated include files. generated_includes = [ + 'cef_color_ids.h', 'cef_command_ids.h', 'cef_config.h', 'cef_pack_resources.h', diff --git a/tools/make_gypi_file.py b/tools/make_gypi_file.py index 581a7b5a9..da66bc005 100644 --- a/tools/make_gypi_file.py +++ b/tools/make_gypi_file.py @@ -8,11 +8,8 @@ from cef_parser import * def make_gypi_file(header): # header string - result = \ -"""# Copyright (c) $YEAR$ The Chromium Embedded Framework Authors. All rights -# reserved. Use of this source code is governed by a BSD-style license that -# can be found in the LICENSE file. -# + result = get_copyright(full=False, translator=False).replace('//', '#') + \ +"""# # --------------------------------------------------------------------------- # # This file was generated by the CEF translator tool and should not edited @@ -80,9 +77,6 @@ def make_gypi_file(header): } """ - # add the copyright year - result = result.replace('$YEAR$', get_year()) - return result diff --git a/tools/make_pack_header.py b/tools/make_pack_header.py index 1afe8d069..5b174e4f3 100644 --- a/tools/make_pack_header.py +++ b/tools/make_pack_header.py @@ -8,7 +8,7 @@ A simple utility function to merge pack resource files into a single resource fi from __future__ import absolute_import from __future__ import print_function -from date_util import * +from cef_parser import get_copyright from file_util import * import os import re @@ -57,36 +57,8 @@ def MakeFileSegment(input, all_names): def MakeFile(output, input): # header string - result = \ -"""// Copyright (c) $YEAR$ Marshall A. Greenblatt. All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the name Chromium Embedded -// Framework nor the names of its contributors may be used to endorse -// or promote products derived from this software without specific prior -// written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// + result = get_copyright(full=True, translator=False) + \ +"""// // --------------------------------------------------------------------------- // // This file is generated by the make_pack_header.py tool. @@ -112,8 +84,6 @@ def MakeFile(output, input): #endif // $GUARD$ """ - # add the copyright year - result = result.replace('$YEAR$', get_year()) # add the guard string filename = os.path.split(output)[1] guard = 'CEF_INCLUDE_' + filename.replace('.', '_').upper() + '_'