Commit cf429990 authored by estark's avatar estark Committed by Commit bot

Fix security icon colors on light themes

Security icon colors on Chrome for Android and Chrome Custom Tabs should
be as follows:

1. Default toolbar color => green lock/red triangle
2. Dark toolbar color => white icons
3. Light toolbar color with opaque omnibox => green/red
4. Other toolbar color with transparent omnibox => dark icons

#1 and #2 were already working properly; this CL implements #3 and #4.

BUG=633736
TEST=On Chrome for Android, visit the following URLs and observe the
given security icon colors:
1. https://google.com => green lock
2. https://yahoo.com => white lock
3. https://just-skyline-137219.appspot.com/lightblue => opaque omnibox
with green lock
4. https://garron.net/test/theme-color/?color=%2300ffff => transparent
omnibox with dark lock
In a CCT client app, set the toolbar color to the following colors and then visit https://www.google.com:
1. Default => green lock
2. #ef6c00 => white lock
3. #ffffcc => dark lock
4. #66ffff => dark lock

Review-Url: https://codereview.chromium.org/2274973004
Cr-Commit-Position: refs/heads/master@{#414897}
parent 31bd9513
...@@ -1226,16 +1226,24 @@ public class LocationBarLayout extends FrameLayout implements OnClickListener, ...@@ -1226,16 +1226,24 @@ public class LocationBarLayout extends FrameLayout implements OnClickListener,
* @param securityLevel The security level for which the color will be returned. * @param securityLevel The security level for which the color will be returned.
* @param provider The {@link ToolbarDataProvider}. * @param provider The {@link ToolbarDataProvider}.
* @param resources The Resources for the Context. * @param resources The Resources for the Context.
* @param isOmniboxOpaque Whether the omnibox is an opaque color.
* @return The {@link ColorStateList} to use to tint the security state icon. * @return The {@link ColorStateList} to use to tint the security state icon.
*/ */
public static ColorStateList getColorStateList( public static ColorStateList getColorStateList(int securityLevel, ToolbarDataProvider provider,
int securityLevel, ToolbarDataProvider provider, Resources resources) { Resources resources, boolean isOmniboxOpaque) {
ColorStateList list = null; ColorStateList list = null;
int color = provider.getPrimaryColor(); int color = provider.getPrimaryColor();
boolean needLightIcon = ColorUtils.shouldUseLightForegroundOnBackground(color); boolean needLightIcon = ColorUtils.shouldUseLightForegroundOnBackground(color);
if (provider.isIncognito() || needLightIcon) { if (provider.isIncognito() || needLightIcon) {
// For a dark theme color, use light icons.
list = ApiCompatibilityUtils.getColorStateList(resources, R.color.light_mode_tint); list = ApiCompatibilityUtils.getColorStateList(resources, R.color.light_mode_tint);
} else if (!ColorUtils.isUsingDefaultToolbarColor(resources, color) && !isOmniboxOpaque) {
// For theme colors which are not dark and are also not
// light enough to warrant an opaque URL bar, use dark
// icons.
list = ApiCompatibilityUtils.getColorStateList(resources, R.color.dark_mode_tint);
} else { } else {
// For the default toolbar color, use a green or red icon.
if (securityLevel == ConnectionSecurityLevel.SECURITY_ERROR) { if (securityLevel == ConnectionSecurityLevel.SECURITY_ERROR) {
list = ApiCompatibilityUtils.getColorStateList(resources, R.color.google_red_700); list = ApiCompatibilityUtils.getColorStateList(resources, R.color.google_red_700);
} else if (securityLevel == ConnectionSecurityLevel.SECURE } else if (securityLevel == ConnectionSecurityLevel.SECURE
...@@ -1261,8 +1269,9 @@ public class LocationBarLayout extends FrameLayout implements OnClickListener, ...@@ -1261,8 +1269,9 @@ public class LocationBarLayout extends FrameLayout implements OnClickListener,
} else { } else {
// ImageView#setImageResource is no-op if given resource is the current one. // ImageView#setImageResource is no-op if given resource is the current one.
mSecurityButton.setImageResource(id); mSecurityButton.setImageResource(id);
mSecurityButton.setTint( mSecurityButton.setTint(getColorStateList(securityLevel, getToolbarDataProvider(),
getColorStateList(securityLevel, getToolbarDataProvider(), getResources())); getResources(), ColorUtils.shouldUseOpaqueTextboxBackground(
getToolbarDataProvider().getPrimaryColor())));
} }
boolean shouldEmphasizeHttpsScheme = shouldEmphasizeHttpsScheme(); boolean shouldEmphasizeHttpsScheme = shouldEmphasizeHttpsScheme();
......
...@@ -507,8 +507,9 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar, ...@@ -507,8 +507,9 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar,
} else { } else {
// ImageView#setImageResource is no-op if given resource is the current one. // ImageView#setImageResource is no-op if given resource is the current one.
mSecurityButton.setImageResource(id); mSecurityButton.setImageResource(id);
mSecurityButton.setTint(LocationBarLayout.getColorStateList( mSecurityButton.setTint(
securityLevel, getToolbarDataProvider(), getResources())); LocationBarLayout.getColorStateList(securityLevel, getToolbarDataProvider(),
getResources(), false /* omnibox is not opaque */));
} }
mAnimDelegate.showSecurityButton(); mAnimDelegate.showSecurityButton();
} }
......
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