Commit 79c5bafe authored by Gayane Petrosyan's avatar Gayane Petrosyan Committed by Commit Bot

[NTP Cleanup] Remove non-white-bg class and other cleanup.

Removing 'non-white-bg' class as search suggestions was the only user
of it and they are not using it anymore.

Bug: None
Change-Id: Icb118c92f4117b6f6a7da5d6c97acdcf994c380d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1811929
Commit-Queue: Gayane Petrosyan <gayane@chromium.org>
Reviewed-by: default avatarKyle Milka <kmilka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699406}
parent 68b2dcd3
......@@ -90,7 +90,6 @@ const CLASSES = {
LEFT_ALIGN_ATTRIBUTION: 'left-align-attribution',
// Vertically centers the most visited section for a non-Google provided page.
NON_GOOGLE_PAGE: 'non-google-page',
NON_WHITE_BG: 'non-white-bg',
SEARCH_ICON: 'search-icon', // Magnifying glass/search icon.
SELECTED: 'selected', // A selected (via up/down arrow key) realbox match.
SHOW_ELEMENT: 'show-element',
......@@ -106,14 +105,6 @@ const SEARCH_HISTORY_MATCH_TYPES = [
'search-suggest-personalized',
];
/**
* Background color for Chrome dark mode. Used to determine if it is possible to
* display a Google Doodle, or if the notifier should be used instead.
* @type {string}
* @const
*/
const DARK_MODE_BACKGROUND_COLOR = 'rgba(53,54,58,1)';
/**
* The period of time (ms) before transitions can be applied to a toast
* notification after modifying the "display" property.
......@@ -244,14 +235,6 @@ const REALBOX_KEYDOWN_HANDLED_KEYS = [
'PageUp',
];
/**
* Background colors considered "white". Used to determine if it is possible to
* display a Google Doodle, or if the notifier should be used instead. Also used
* to determine if a colored or white logo should be used.
* @const
*/
const WHITE_BACKGROUND_COLORS = ['rgba(255,255,255,1)', 'rgba(0,0,0,0)'];
// Local statics.
/** @type {!Array<!AutocompleteMatch>} */
......@@ -1486,23 +1469,10 @@ function renderTheme() {
isDarkModeEnabled = window.matchMedia('(prefers-color-scheme: dark)').matches;
document.body.classList.toggle('light-chip', !getUseDarkChips(info));
const background = [
convertToRGBAColor(info.backgroundColorRgba), info.imageUrl,
info.imageTiling, info.imageHorizontalAlignment, info.imageVerticalAlignment
].join(' ').trim();
// If a custom background has been selected the image will be applied to the
// custom-background element instead of the body.
if (!info.customBackgroundConfigured) {
document.body.style.background = background;
}
// Dark mode uses a white Google logo.
const useWhiteLogo =
info.alternateLogo || (info.usingDefaultTheme && isDarkModeEnabled);
document.body.classList.toggle(CLASSES.ALTERNATE_LOGO, useWhiteLogo);
const isNonWhiteBackground = !WHITE_BACKGROUND_COLORS.includes(background);
document.body.classList.toggle(CLASSES.NON_WHITE_BG, isNonWhiteBackground);
if (info.logoColor) {
document.body.style.setProperty(
......@@ -1512,14 +1482,22 @@ function renderTheme() {
// The doodle notifier should be shown for non-default backgrounds. This
// includes non-white backgrounds, excluding dark mode gray if dark mode is
// enabled.
const isDefaultBackground = WHITE_BACKGROUND_COLORS.includes(background) ||
(isDarkModeEnabled && background === DARK_MODE_BACKGROUND_COLOR);
const isDefaultBackground = info.usingDefaultTheme && !info.imageUrl;
document.body.classList.toggle(CLASSES.USE_NOTIFIER, !isDefaultBackground);
updateThemeAttribution(info.attributionUrl, info.imageHorizontalAlignment);
setCustomThemeStyle(info);
// If a custom background has been selected the image will be applied to the
// custom-background element instead of the body.
if (!info.customBackgroundConfigured) {
document.body.style.background = [
convertToRGBAColor(info.backgroundColorRgba), info.imageUrl,
info.imageTiling, info.imageHorizontalAlignment,
info.imageVerticalAlignment
].join(' ').trim();
if (info.customBackgroundConfigured) {
$(IDS.CUSTOM_BG).style.opacity = '0';
$(IDS.CUSTOM_BG).style.backgroundImage = '';
customize.clearAttribution();
} else {
// Do anything only if the custom background changed.
const imageUrl = assert(info.imageUrl);
if (!$(IDS.CUSTOM_BG).style.backgroundImage.includes(imageUrl)) {
......@@ -1549,12 +1527,11 @@ function renderTheme() {
'' + info.attribution1, '' + info.attribution2,
'' + info.attributionActionUrl);
}
} else {
$(IDS.CUSTOM_BG).style.opacity = '0';
$(IDS.CUSTOM_BG).style.backgroundImage = '';
customize.clearAttribution();
}
updateThemeAttribution(info.attributionUrl, info.imageHorizontalAlignment);
setCustomThemeStyle(info);
$(customize.IDS.RESTORE_DEFAULT)
.classList.toggle(
customize.CLASSES.OPTION_DISABLED, !info.customBackgroundConfigured);
......
......@@ -28,6 +28,7 @@
#include "extensions/browser/extension_registry.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/color_utils.h"
class TestThemeInfoObserver : public InstantServiceObserver {
public:
......@@ -39,9 +40,8 @@ class TestThemeInfoObserver : public InstantServiceObserver {
void WaitForThemeApplied(bool theme_installed) {
DCHECK(!quit_closure_);
theme_installed_ = theme_installed;
if (!theme_info_.using_default_theme == theme_installed) {
if (hasThemeInstalled(theme_info_) == theme_installed_) {
return;
}
......@@ -50,13 +50,11 @@ class TestThemeInfoObserver : public InstantServiceObserver {
run_loop.Run();
}
bool IsUsingDefaultTheme() { return theme_info_.using_default_theme; }
private:
void ThemeInfoChanged(const ThemeBackgroundInfo& theme_info) override {
theme_info_ = theme_info;
if (quit_closure_ && !theme_info_.using_default_theme == theme_installed_) {
if (quit_closure_ && hasThemeInstalled(theme_info) == theme_installed_) {
std::move(quit_closure_).Run();
quit_closure_.Reset();
}
......@@ -64,6 +62,10 @@ class TestThemeInfoObserver : public InstantServiceObserver {
void MostVisitedInfoChanged(const InstantMostVisitedInfo&) override {}
bool hasThemeInstalled(const ThemeBackgroundInfo& theme_info) {
return theme_info.theme_id != "";
}
InstantService* const service_;
ThemeBackgroundInfo theme_info_;
......@@ -224,7 +226,6 @@ IN_PROC_BROWSER_TEST_F(InstantThemeTest, ThemeAppliedToNewTab) {
const std::string helper_js = "document.body.style.cssText";
TestThemeInfoObserver observer(
InstantServiceFactory::GetForProfile(browser()->profile()));
// Open new tab.
content::WebContents* active_tab =
local_ntp_test_utils::OpenNewTab(browser(), GURL("about:blank"));
......
......@@ -345,7 +345,6 @@ test.customizeMenu.testMenu_BackgroundPreviewApplied = function() {
// Check that correct styling is applied to the page.
assertTrue(document.body.classList.contains('alternate-logo'));
assertTrue(document.body.classList.contains('non-white-bg'));
};
/**
......
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