Skip to content

Commit

Permalink
Add dark theme for dev channel
Browse files Browse the repository at this point in the history
  • Loading branch information
bbondy committed Aug 15, 2018
1 parent 96f66cc commit bc779a4
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 0 deletions.
1 change: 1 addition & 0 deletions browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ source_set("browser_process") {
"//components/spellcheck/browser",
"//content/public/browser",
"//brave/chromium_src:browser",
"themes",
]

if (is_win && is_official_build) {
Expand Down
9 changes: 9 additions & 0 deletions browser/themes/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
source_set("themes") {
sources = [
"theme_properties.cc",
"theme_properties.h",
]
deps = [
"//skia",
]
}
91 changes: 91 additions & 0 deletions browser/themes/theme_properties.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/browser/themes/theme_properties.h"

#include "chrome/browser/themes/theme_properties.h"
#include "chrome/common/channel_info.h"
#include "ui/gfx/color_palette.h"

namespace {

#if defined(OFFICIAL_BUILD)
base::Optional<SkColor> MaybeGetDefaultColorForBraveUiReleaseChannel(int id, bool incognito) {
switch (id) {
// Applies when the window is active, tabs and also tab bar everywhere except active tab
case ThemeProperties::COLOR_FRAME:
case ThemeProperties::COLOR_BACKGROUND_TAB:
return incognito ? SkColorSetRGB(0x81, 0x85, 0x89) : SkColorSetRGB(0xD8, 0xDE, 0xE1);
// Window when the window is innactive, tabs and also tab bar everywhere except active tab
case ThemeProperties::COLOR_FRAME_INACTIVE:
case ThemeProperties::COLOR_BACKGROUND_TAB_INACTIVE:
return incognito ? SkColorSetRGB(0x71, 0x75, 0x79) : SkColorSetRGB(0xC8, 0xCE, 0xC8);
// Active tab and also the URL toolbar
// Parts of this color show up as you hover over innactive tabs too
case ThemeProperties::COLOR_TOOLBAR:
case ThemeProperties::COLOR_DETACHED_BOOKMARK_BAR_BACKGROUND:
case ThemeProperties::COLOR_CONTROL_BACKGROUND:
case ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR:
return incognito ? SkColorSetRGB(0x91, 0x95, 0x99) : SkColorSetRGB(0xF6, 0xF7, 0xF9);
case ThemeProperties::COLOR_TAB_TEXT:
return SkColorSetRGB(0x22, 0x23, 0x26);
case ThemeProperties::COLOR_BOOKMARK_TEXT:
case ThemeProperties::COLOR_BACKGROUND_TAB_TEXT:
return SkColorSetRGB(0x22, 0x23, 0x26);
default:
return base::nullopt;
}
}
#endif

base::Optional<SkColor> MaybeGetDefaultColorForBraveUiDevChannel(int id, bool incognito) {
switch (id) {
// Applies when the window is active, tabs and also tab bar everywhere except active tab
case ThemeProperties::COLOR_FRAME:
case ThemeProperties::COLOR_BACKGROUND_TAB:
return incognito ? SkColorSetRGB(0x68, 0x6B, 0x6E) : SkColorSetRGB(0x58, 0x5B, 0x5E);
// Window when the window is innactive, tabs and also tab bar everywhere except active tab
case ThemeProperties::COLOR_FRAME_INACTIVE:
case ThemeProperties::COLOR_BACKGROUND_TAB_INACTIVE:
return incognito ? SkColorSetRGB(0x58, 0x5B, 0x5E) : SkColorSetRGB(0x48, 0x4B, 0x4E);
// Active tab and also the URL toolbar
// Parts of this color show up as you hover over innactive tabs too
case ThemeProperties::COLOR_TOOLBAR:
case ThemeProperties::COLOR_DETACHED_BOOKMARK_BAR_BACKGROUND:
case ThemeProperties::COLOR_CONTROL_BACKGROUND:
case ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR:
return incognito ? SkColorSetRGB(0x32, 0x33, 0x36) : SkColorSetRGB(0x22, 0x23, 0x26);
case ThemeProperties::COLOR_TAB_TEXT:
return SkColorSetRGB(0xF7, 0xF8, 0xF9);
case ThemeProperties::COLOR_BOOKMARK_TEXT:
case ThemeProperties::COLOR_BACKGROUND_TAB_TEXT:
return SkColorSetRGB(0x81, 0x85, 0x89);
default:
return base::nullopt;
}
}

} // namespace

// Returns a |nullopt| if the UI color is not handled by Brave.
base::Optional<SkColor> MaybeGetDefaultColorForBraveUi(int id, bool incognito) {
if (id == BRAVE_COLOR_FOR_TEST) {
return SkColorSetRGB(11, 13, 17);
}
#if !defined(OFFICIAL_BUILD)
return MaybeGetDefaultColorForBraveUiDevChannel(id, incognito);
#else
switch (chrome::GetChannel()) {
case version_info::Channel::STABLE:
case version_info::Channel::BETA:
return MaybeGetDefaultColorForBraveUiReleaseChannel(id, incognito);
case version_info::Channel::DEV:
case version_info::Channel::CANARY:
case version_info::Channel::UNKNOWN:
default:
return MaybeGetDefaultColorForBraveUiDevChannel(id, incognito);
}
#endif
return base::nullopt;
}
19 changes: 19 additions & 0 deletions browser/themes/theme_properties.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_BROWSER_THEMES_THEME_PROPERTIES_H_
#define BRAVE_BROWSER_THEMES_THEME_PROPERTIES_H_

#include "base/optional.h"
#include "third_party/skia/include/core/SkColor.h"

#define BRAVE_COLOR_FOR_TEST 0x7FFFFFFF

base::Optional<SkColor> MaybeGetDefaultColorForBraveUi(int id, bool incognito);

#define MAYBE_OVERRIDE_DEFAULT_COLOR_FOR_BRAVE(id, incognito) \
const base::Optional<SkColor> braveColor = MaybeGetDefaultColorForBraveUi(id, incognito); \
if (braveColor) return braveColor.value();

#endif // BRAVE_BROWSER_THEMES_THEME_PROPERTIES_H_
13 changes: 13 additions & 0 deletions browser/themes/theme_properties_unittest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/browser/themes/theme_properties.h"
#include "chrome/browser/themes/theme_properties.h"
#include "testing/gtest/include/gtest/gtest.h"

TEST(BraveThemeTest, ObtainsBraveOverrideColors) {
SkColor actualColor = ThemeProperties::GetDefaultColor(BRAVE_COLOR_FOR_TEST, false);
SkColor expectedColor = SkColorSetRGB(11, 13, 17);
ASSERT_EQ(actualColor, expectedColor);
}
20 changes: 20 additions & 0 deletions patches/chrome-browser-themes-theme_properties.cc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
diff --git a/chrome/browser/themes/theme_properties.cc b/chrome/browser/themes/theme_properties.cc
index 135c5029bb1aeeab1be398388db47392069ec0c5..af1105e469f8935f55160f86220a2d38757a450d 100644
--- a/chrome/browser/themes/theme_properties.cc
+++ b/chrome/browser/themes/theme_properties.cc
@@ -10,6 +10,7 @@
#include "base/optional.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
+#include "brave/browser/themes/theme_properties.h"
#include "build/build_config.h"
#include "chrome/browser/themes/browser_theme_pack.h"
#include "ui/base/material_design/material_design_controller.h"
@@ -290,6 +291,7 @@ color_utils::HSL ThemeProperties::GetDefaultTint(int id, bool incognito) {

// static
SkColor ThemeProperties::GetDefaultColor(int id, bool incognito) {
+ MAYBE_OVERRIDE_DEFAULT_COLOR_FOR_BRAVE(id, incognito)
const base::Optional<SkColor> color =
MaybeGetDefaultColorForNewerMaterialUi(id, incognito);
if (color)
1 change: 1 addition & 0 deletions test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ test("brave_unit_tests") {
"//brave/browser/brave_stats_updater_unittest.cc",
"//brave/browser/net/brave_site_hacks_network_delegate_helper_unittest.cc",
"//brave/browser/net/brave_static_redirect_network_delegate_helper_unittest.cc",
"//brave/browser/themes/theme_properties_unittest.cc",
"//brave/chromium_src/chrome/browser/signin/account_consistency_disabled_unittest.cc",
"//brave/chromium_src/components/version_info/brave_version_info_unittest.cc",
"//brave/common/importer/brave_mock_importer_bridge.cc",
Expand Down

0 comments on commit bc779a4

Please sign in to comment.