Commit b7b70a69 authored by Lijin Shen's avatar Lijin Shen Committed by Commit Bot

[snowflake] Move one-off colors and update presubmit warning description

1. create one_off_colors.xml exclusively for one-off colors
2. update presubmit warning description

Bug: 775198
Change-Id: I9129c32ea58e4d35543d7f6cc152252048c1a685
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2057448
Commit-Queue: Lijin Shen <lazzzis@chromium.org>
Reviewed-by: default avatarJohn Budorick <jbudorick@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742369}
parent 7f8cb314
......@@ -77,7 +77,10 @@ def _CheckColorFormat(input_api, output_api):
This is banned, please define colors in format of #RRGGBB for opaque
colors or #AARRGGBB for translucent colors. Note that they should be
defined in chrome/android/java/res/values/colors.xml.
defined in chrome/android/java/res/values/color_palette.xml.
If the new added color is a one-off color, please contact UX for approval
and then add it to ui/android/java/res/values/one_off_colors.xml
See https://crbug.com/775198 for more information.
''', errors)
......@@ -86,11 +89,15 @@ def _CheckColorFormat(input_api, output_api):
def _CheckColorReferences(input_api, output_api):
"""Checks no (A)RGB values are defined outside color_palette.xml."""
"""
Checks no (A)RGB values are defined outside color_palette.xml
or one_off_colors.xml.
"""
errors = []
warnings = []
for f in IncludedFiles(input_api):
if f.LocalPath() == helpers.COLOR_PALETTE_RELATIVE_PATH:
if (f.LocalPath() == helpers.COLOR_PALETTE_RELATIVE_PATH
or f.LocalPath() == helpers.ONE_OFF_COLORS_RELATIVE_PATH):
continue
# Ignore new references in vector/shape drawable xmls
contents = input_api.ReadFile(f)
......@@ -112,7 +119,10 @@ def _CheckColorReferences(input_api, output_api):
ui/android/java/res/values/color_palette.xml, listed below.
This is banned, please use the existing color resources or create a new
color resource in colors.xml, and reference the color by @color/....
color resource in color_palette.xml, and reference the color by @color/....
If the new added color is a one-off color, please contact UX for approval
and then add it to ui/android/java/res/values/one_off_colors.xml.
See https://crbug.com/775198 for more information.
''', errors)
......@@ -139,10 +149,14 @@ def _CheckColorReferences(input_api, output_api):
def _CheckDuplicateColors(input_api, output_api):
"""Checks colors defined by (A)RGB values in color_palette.xml are unique."""
"""
Checks colors defined by (A)RGB values in color_palette.xml and
one_off_colors.xml are unique.
"""
errors = []
for f in IncludedFiles(input_api):
if f.LocalPath() != helpers.COLOR_PALETTE_RELATIVE_PATH:
if (f.LocalPath() != helpers.COLOR_PALETTE_RELATIVE_PATH
and f.LocalPath() != helpers.ONE_OFF_COLORS_RELATIVE_PATH):
continue
colors = defaultdict(int)
contents = input_api.ReadFile(f)
......@@ -164,11 +178,12 @@ def _CheckDuplicateColors(input_api, output_api):
'''
Android Duplicate Color Declaration Check failed:
Your new code added new colors by (A)RGB values that are already defined in
ui/android/java/res/values/color_palette.xml, listed below.
ui/android/java/res/values/color_palette.xml or
ui/android/java/res/values/one_off_colors.xml, listed below.
This is banned, please reference the existing color resource from colors.xml
using @color/... and if needed, give the existing color resource a more
general name (e.g. modern_grey_100).
This is banned, please reference the existing color resource from
color_palette.xml or one_off_colors.xml using @color/... and if needed,
give the existing color resource a more general name (e.g. modern_grey_100).
See https://crbug.com/775198 for more information.
''', errors)
......@@ -179,7 +194,7 @@ def _CheckDuplicateColors(input_api, output_api):
def _CheckSemanticColorsReferences(input_api, output_api):
"""
Checks colors defined in semantic_colors.xml only referencing
resources in color_palette.xml
resources in color_palette.xml.
"""
errors = []
color_palette = None
......
......@@ -138,11 +138,12 @@ class ColorReferencesTest(unittest.TestCase):
def testReferenceInSemanticColors(self):
mock_input_api = MockInputApi()
mock_input_api.files = [
MockFile(helpers.COLOR_PALETTE_PATH,
['<resources><color name="a">#f0f0f0</color></resources>']),
MockFile('ui/android/java/res/values/semantic_colors.xml',
['<color name="b">@color/hello<color>',
'<color name="c">@color/a<color>'])
MockFile(helpers.COLOR_PALETTE_PATH,
['<resources><color name="a">#f0f0f0</color></resources>']),
MockFile('ui/android/java/res/values/semantic_colors.xml', [
'<color name="b">@color/hello<color>',
'<color name="c">@color/a<color>'
])
]
errors = checkxmlstyle._CheckSemanticColorsReferences(
mock_input_api, MockOutputApi())
......
......@@ -9,6 +9,8 @@ _SRC_ROOT = os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', '..', '..'))
COLOR_PALETTE_RELATIVE_PATH = 'ui/android/java/res/values/color_palette.xml'
COLOR_PALETTE_PATH = os.path.join(_SRC_ROOT, COLOR_PALETTE_RELATIVE_PATH)
ONE_OFF_COLORS_RELATIVE_PATH = 'ui/android/java/res/values/one_off_colors.xml'
ONE_OFF_COLORS_PATH = os.path.join(_SRC_ROOT, ONE_OFF_COLORS_RELATIVE_PATH)
SEMANTIC_COLORS_PATH = os.path.join(_SRC_ROOT,
'ui/android/java/res/values/semantic_colors.xml')
BUTTOM_COMPAT_WIDGET_RELATIVE_PATH = (
......
......@@ -60,26 +60,4 @@
<!-- Only use for older versions of Android mimics UI. -->
<color name="google_blue_grey_900" tools:ignore="UnusedResources">#263238</color>
<color name="google_blue_50" tools:ignore="UnusedResources">#E3F2FD</color>
<!-- Warning: One off below, do not use for other purpose. -->
<color name="signin_header_animation_bg_dark" tools:ignore="UnusedResources">#28282B</color>
<!-- TODO(https://crbug.com/1020436): Update the highlight colors to meet accessibility
contrast ratio. -->
<color name="highlight_color_on_light_text" tools:ignore="UnusedResources">#CC5595FE</color>
<color name="highlight_color_on_dark_text" tools:ignore="UnusedResources">#C6DAFC</color>
<color name="black_alpha_12" tools:ignore="UnusedResources">#1F000000</color>
<color name="black_alpha_20" tools:ignore="UnusedResources">#33000000</color>
<color name="black_alpha_30" tools:ignore="UnusedResources">#4D000000</color>
<color name="white_alpha_65" tools:ignore="UnusedResources">#A6FFFFFF</color>
<color name="white_alpha_75" tools:ignore="UnusedResources">#BFFFFFFF</color>
<color name="find_result_bar_result" tools:ignore="UnusedResources">#FFDE43</color>
<color name="find_result_bar_result_border" tools:ignore="UnusedResources">#C9AF35</color>
<color name="find_result_bar_active" tools:ignore="UnusedResources">#FF9632</color>
<color name="find_result_bar_active_border" tools:ignore="UnusedResources">#C37E3B</color>
<color name="progress_bar_background_deprecated" tools:ignore="UnusedResources">#3D4386F7</color>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2020 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.
-->
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Warning: One off below, do not use for other purpose.
Ask for a UX approval before adding a new one.
-->
<color name="signin_header_animation_bg_dark" tools:ignore="UnusedResources">#28282B</color>
<!-- TODO(https://crbug.com/1020436): Update the highlight colors to meet accessibility
contrast ratio. -->
<color name="highlight_color_on_light_text" tools:ignore="UnusedResources">#CC5595FE</color>
<color name="highlight_color_on_dark_text" tools:ignore="UnusedResources">#C6DAFC</color>
<color name="black_alpha_12" tools:ignore="UnusedResources">#1F000000</color>
<color name="black_alpha_20" tools:ignore="UnusedResources">#33000000</color>
<color name="black_alpha_30" tools:ignore="UnusedResources">#4D000000</color>
<color name="white_alpha_65" tools:ignore="UnusedResources">#A6FFFFFF</color>
<color name="white_alpha_75" tools:ignore="UnusedResources">#BFFFFFFF</color>
<color name="find_result_bar_result" tools:ignore="UnusedResources">#FFDE43</color>
<color name="find_result_bar_result_border" tools:ignore="UnusedResources">#C9AF35</color>
<color name="find_result_bar_active" tools:ignore="UnusedResources">#FF9632</color>
<color name="find_result_bar_active_border" tools:ignore="UnusedResources">#C37E3B</color>
<color name="progress_bar_background_deprecated" tools:ignore="UnusedResources">#3D4386F7</color>
</resources>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment