Commit c860e740 authored by Tomasz Wiszkowski's avatar Tomasz Wiszkowski Committed by Commit Bot

Use dark theme controlled palette for UrlBar text colors.

This change:
- reduces code complexity and dependency on duplicate resources,
- fixes a glitch on Android P and Q where text colors would not be
  correctly reflected by the theme,
- drops redundant color definitions.

Bug: 944496

Change-Id: I3058edc9c6414ead398bb4e7f3d223fd0a8c77d8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1536541Reviewed-by: default avatarYusuf Ozuysal <yusufo@chromium.org>
Reviewed-by: default avatarBecky Zhou <huayinz@chromium.org>
Commit-Queue: Ender <ender@google.com>
Cr-Commit-Position: refs/heads/master@{#644378}
parent e7bed62b
......@@ -73,9 +73,6 @@
<color name="url_emphasis_light_non_emphasized_text">@color/white_alpha_50</color>
<color name="url_emphasis_domain_and_registry">#333333</color>
<color name="url_emphasis_light_domain_and_registry">@android:color/white</color>
<color name="url_emphasis_default_text">@color/modern_grey_900</color>
<!--suppress UnusedResources -->
<color name="url_emphasis_light_default_text">@android:color/white</color>
<!-- Omnibox Suggestion colors -->
<color name="suggestion_url_dark_modern">@color/default_text_color_link</color>
......
......@@ -51,7 +51,6 @@ import org.chromium.chrome.browser.preferences.privacy.PrivacyPreferencesManager
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.search_engines.TemplateUrlService;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.toolbar.LocationBarModel;
import org.chromium.chrome.browser.toolbar.ToolbarDataProvider;
import org.chromium.chrome.browser.toolbar.ToolbarManager;
import org.chromium.chrome.browser.toolbar.top.ToolbarActionModeCallback;
......@@ -105,8 +104,7 @@ public class LocationBarLayout extends FrameLayout
private OmniboxPrerender mOmniboxPrerender;
private boolean mUseDarkColors;
private boolean mOmniboxVoiceSearchAlwaysVisible;
protected float mUrlFocusChangePercent;
protected LinearLayout mUrlActionContainer;
......@@ -1024,22 +1022,21 @@ public class LocationBarLayout extends FrameLayout
ColorUtils.getDefaultThemeColor(getResources(), mToolbarDataProvider.isIncognito());
final int primaryColor =
mUrlHasFocus ? defaultPrimaryColor : mToolbarDataProvider.getPrimaryColor();
mUseDarkColors =
LocationBarModel.shouldUseDarkColors(mToolbarDataProvider.hasTab(), primaryColor);
final boolean useDarkColors = !ColorUtils.shouldUseLightForegroundOnBackground(primaryColor);
int id = ColorUtils.getIconTintRes(!mUseDarkColors);
int id = ColorUtils.getIconTintRes(!useDarkColors);
ColorStateList colorStateList = AppCompatResources.getColorStateList(getContext(), id);
ApiCompatibilityUtils.setImageTintList(mMicButton, colorStateList);
ApiCompatibilityUtils.setImageTintList(mDeleteButton, colorStateList);
// If the URL changed colors and is not focused, update the URL to account for the new
// color scheme.
if (mUrlCoordinator.setUseDarkTextColors(mUseDarkColors) && !mUrlBar.hasFocus()) {
if (mUrlCoordinator.setUseDarkTextColors(useDarkColors) && !mUrlBar.hasFocus()) {
setUrlToPageUrl();
}
mStatusViewCoordinator.setUseDarkColors(mUseDarkColors);
mAutocompleteCoordinator.updateVisualsForState(mUseDarkColors);
mStatusViewCoordinator.setUseDarkColors(useDarkColors);
mAutocompleteCoordinator.updateVisualsForState(useDarkColors);
}
@Override
......
......@@ -183,8 +183,8 @@ public class OmniboxUrlEmphasizer {
// Draw attention to the data: URI scheme for anti-spoofing reasons.
if (UrlConstants.DATA_SCHEME.equals(
emphasizeResponse.extractScheme(urlString))) {
colorId = useDarkColors ? R.color.url_emphasis_default_text
: R.color.url_emphasis_light_default_text;
colorId = useDarkColors ? R.color.default_text_color_dark
: R.color.default_text_color_light;
}
break;
case ConnectionSecurityLevel.DANGEROUS:
......
......@@ -91,14 +91,12 @@ class UrlBarViewBinder {
int hintColor;
int highlightColor;
if (useDarkTextColors) {
textColor =
ApiCompatibilityUtils.getColor(resources, R.color.url_emphasis_default_text);
textColor = ApiCompatibilityUtils.getColor(resources, R.color.default_text_color_dark);
hintColor =
ApiCompatibilityUtils.getColor(resources, R.color.locationbar_dark_hint_text);
highlightColor = originalHighlightColor;
} else {
textColor = ApiCompatibilityUtils.getColor(
resources, R.color.url_emphasis_light_default_text);
textColor = ApiCompatibilityUtils.getColor(resources, R.color.default_text_color_light);
hintColor =
ApiCompatibilityUtils.getColor(resources, R.color.locationbar_light_hint_text);
highlightColor = ApiCompatibilityUtils.getColor(
......
......@@ -131,8 +131,10 @@ public class BasicSuggestionProcessor implements SuggestionProcessor {
if ((suggestionType == OmniboxSuggestionType.SEARCH_SUGGEST_ENTITY)
|| (suggestionType == OmniboxSuggestionType.SEARCH_SUGGEST_PROFILE)) {
textLine2 = SpannableString.valueOf(suggestion.getDescription());
textLine2Color = SuggestionViewViewBinder.getStandardFontColor(
mContext, model.get(SuggestionCommonProperties.USE_DARK_COLORS));
textLine2Color = ApiCompatibilityUtils.getColor(mContext.getResources(),
model.get(SuggestionCommonProperties.USE_DARK_COLORS)
? R.color.default_text_color_dark
: R.color.default_text_color_light);
textLine2Direction = View.TEXT_DIRECTION_INHERIT;
} else if (mEnableNewAnswerLayout
&& suggestionType == OmniboxSuggestionType.CALCULATOR) {
......
......@@ -4,9 +4,6 @@
package org.chromium.chrome.browser.omnibox.suggestions.basic;
import android.content.Context;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;
import android.support.v4.view.ViewCompat;
import android.text.Spannable;
import android.text.TextUtils;
......@@ -37,7 +34,9 @@ public class SuggestionViewViewBinder {
view.updateRefineIconTint(useDarkColors);
view.updateSuggestionIconTint(useDarkColors);
view.getTextLine1().setTextColor(
getStandardFontColor(view.getContext(), useDarkColors));
ApiCompatibilityUtils.getColor(view.getContext().getResources(),
useDarkColors ? R.color.default_text_color_dark
: R.color.default_text_color_light));
} else if (SuggestionCommonProperties.LAYOUT_DIRECTION.equals(propertyKey)) {
ViewCompat.setLayoutDirection(
view, model.get(SuggestionCommonProperties.LAYOUT_DIRECTION));
......@@ -157,18 +156,4 @@ public class SuggestionViewViewBinder {
: SuggestionView.SuggestionLayoutType.ANSWER);
}
}
/**
* Get the appropriate font color to be used for non-URL text in suggestions.
* @param context The context to load the color.
* @param useDarkColors Whether dark colors should be used.
* @return The font color to be used.
*/
@ColorInt
public static int getStandardFontColor(Context context, boolean useDarkColors) {
@ColorRes
int res = useDarkColors ? R.color.url_emphasis_default_text
: R.color.url_emphasis_light_default_text;
return ApiCompatibilityUtils.getColor(context.getResources(), res);
}
}
......@@ -5,7 +5,6 @@
package org.chromium.chrome.browser.toolbar;
import android.content.Context;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
......@@ -225,7 +224,8 @@ public class LocationBarModel implements ToolbarDataProvider {
OmniboxUrlEmphasizer.emphasizeUrl(spannableDisplayText, mContext.getResources(),
getProfile(), getSecurityLevel(), isInternalPage,
shouldUseDarkColors(hasTab(), getPrimaryColor()), shouldEmphasizeHttpsScheme());
!ColorUtils.shouldUseLightForegroundOnBackground(getPrimaryColor()),
shouldEmphasizeHttpsScheme());
}
return UrlBarData.forUrlAndText(url, spannableDisplayText, editingText);
......@@ -250,16 +250,6 @@ public class LocationBarModel implements ToolbarDataProvider {
return !isUsingBrandColor() && !isIncognito();
}
/**
* @param hasTab Whether the location is attached to a {@link Tab}. See
* {@link ToolbarDataProvider#hasTab()}.
* @param primaryColor The primary color of the toolbar that holds this location bar.
* @return Whether or not dark text color or icon tint should be used for the location bar.
*/
public static boolean shouldUseDarkColors(boolean hasTab, @ColorInt int primaryColor) {
return !hasTab || !ColorUtils.shouldUseLightForegroundOnBackground(primaryColor);
}
@Override
public String getTitle() {
if (!hasTab()) return "";
......
......@@ -496,11 +496,9 @@ public class CustomTabToolbar
setUrlToPageUrl();
}
int titleTextColor = mUseDarkColors
? ApiCompatibilityUtils.getColor(resources, R.color.url_emphasis_default_text)
: ApiCompatibilityUtils.getColor(
resources, R.color.url_emphasis_light_default_text);
mTitleBar.setTextColor(titleTextColor);
mTitleBar.setTextColor(ApiCompatibilityUtils.getColor(resources,
mUseDarkColors ? R.color.default_text_color_dark
: R.color.default_text_color_light));
if (getProgressBar() != null) {
if (!ColorUtils.isUsingDefaultToolbarColor(
......
......@@ -294,7 +294,7 @@ public class OmniboxUrlEmphasizerTest {
Assert.assertEquals("Unexpected number of spans:", 2, spans.length);
spans[0].assertIsColoredSpan("data", 0,
ApiCompatibilityUtils.getColor(mResources, R.color.url_emphasis_default_text));
ApiCompatibilityUtils.getColor(mResources, R.color.default_text_color_dark));
spans[1].assertIsColoredSpan(":text/plain;charset=utf-8;base64,VGVzdCBVUkw=", 4,
ApiCompatibilityUtils.getColor(
mResources, R.color.url_emphasis_non_emphasized_text));
......
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