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