-
Notifications
You must be signed in to change notification settings - Fork 892
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #361 from brave/brave_theme_option
Add brave theme option to settings page
- Loading branch information
Showing
13 changed files
with
319 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
browser/resources/settings/brave_appearance_page/brave_appearance_browser_proxy.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<link rel="href" src="chrome://resources/html/cr.html"> | ||
<script src="brave_appearance_browser_proxy.js"></script> |
39 changes: 39 additions & 0 deletions
39
browser/resources/settings/brave_appearance_page/brave_appearance_browser_proxy.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* 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/. */ | ||
|
||
cr.define('settings', function() { | ||
/** @interface */ | ||
class BraveAppearanceBrowserProxy { | ||
/** | ||
* @return {!Promise<string>} | ||
*/ | ||
getBraveThemeType() {} | ||
/** | ||
* @param {string} theme name. | ||
*/ | ||
setBraveThemeType(theme) {} | ||
} | ||
|
||
/** | ||
* @implements {settings.BraveAppearanceBrowserProxy} | ||
*/ | ||
class BraveAppearanceBrowserProxyImpl { | ||
/** @override */ | ||
getBraveThemeType() { | ||
return cr.sendWithPromise('getBraveThemeType'); | ||
} | ||
|
||
/** @override */ | ||
setBraveThemeType(theme) { | ||
chrome.send('setBraveThemeType', [theme]); | ||
} | ||
} | ||
|
||
cr.addSingletonGetter(BraveAppearanceBrowserProxyImpl); | ||
|
||
return { | ||
BraveAppearanceBrowserProxy: BraveAppearanceBrowserProxy, | ||
BraveAppearanceBrowserProxyImpl: BraveAppearanceBrowserProxyImpl, | ||
}; | ||
}); |
27 changes: 27 additions & 0 deletions
27
browser/resources/settings/brave_appearance_page/brave_appearance_page.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<link rel="import" href="chrome://resources/html/polymer.html"> | ||
|
||
<link rel="import" href="chrome://resources/html/i18n_behavior.html"> | ||
<link rel="import" href="chrome://resources/html/md_select_css.html"> | ||
<link rel="import" href="brave_appearance_browser_proxy.html"> | ||
<link rel="import" href="../settings_shared_css.html"> | ||
<link rel="import" href="../settings_vars_css.html"> | ||
|
||
<dom-module id="settings-brave-appearance-page"> | ||
<template> | ||
<style include="settings-shared md-select iron-flex"> | ||
</style> | ||
<div class="settings-box"> | ||
<div class="start">$i18n{appearanceSettingsBraveTheme}</div> | ||
<select id="braveThemeType" class="md-select" | ||
on-change="onBraveThemeTypeChange_"> | ||
<template is="dom-repeat" items="[[braveThemeTypes_]]"> | ||
<option value="[[item]]" | ||
selected="[[braveThemeTypeEqual_(item, braveThemeType_)]]"> | ||
[[item]] | ||
</option> | ||
</template> | ||
</select> | ||
</div> | ||
</template> | ||
<script src="brave_appearance_page.js"></script> | ||
</dom-module> |
57 changes: 57 additions & 0 deletions
57
browser/resources/settings/brave_appearance_page/brave_appearance_page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* 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/. */ | ||
|
||
(function() { | ||
'use strict'; | ||
|
||
/** | ||
* 'settings-brave-appearance-page' is the settings page containing brave's | ||
* appearance settings. | ||
*/ | ||
Polymer({ | ||
is: 'settings-brave-appearance-page', | ||
|
||
properties: { | ||
braveThemeTypes_: { | ||
readOnly: true, | ||
type: Array, | ||
value: [ | ||
'Default', | ||
'Light', | ||
'Dark', | ||
], | ||
}, | ||
braveThemeType_: String, | ||
}, | ||
|
||
/** @private {?settings.BraveAppearanceBrowserProxy} */ | ||
browserProxy_: null, | ||
|
||
/** @override */ | ||
created: function() { | ||
this.browserProxy_ = settings.BraveAppearanceBrowserProxyImpl.getInstance(); | ||
}, | ||
|
||
/** @override */ | ||
ready: function() { | ||
this.browserProxy_.getBraveThemeType().then(theme => { | ||
this.braveThemeType_ = theme; | ||
}); | ||
}, | ||
|
||
/** | ||
* @param {string} theme1 | ||
* @param {string} theme2 | ||
* @return {boolean} | ||
* @private | ||
*/ | ||
braveThemeTypeEqual_: function(theme1, theme2) { | ||
return theme1 === theme2; | ||
}, | ||
|
||
onBraveThemeTypeChange_: function() { | ||
this.browserProxy_.setBraveThemeType(this.$.braveThemeType.value); | ||
}, | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* 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/ui/webui/settings/brave_appearance_handler.h" | ||
|
||
#include <string> | ||
|
||
#include "base/bind.h" | ||
#include "base/values.h" | ||
#include "brave/browser/themes/brave_theme_service.h" | ||
#include "brave/common/pref_names.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "components/prefs/pref_service.h" | ||
#include "content/public/browser/web_ui.h" | ||
|
||
namespace { | ||
void SetBraveThemeTypePref(Profile* profile, | ||
BraveThemeService::BraveThemeType type) { | ||
profile->GetPrefs()->SetInteger(kBraveThemeType, type); | ||
} | ||
|
||
BraveThemeService::BraveThemeType GetBraveThemeTypeFromString( | ||
base::StringPiece theme) { | ||
if (theme == "Default") | ||
return BraveThemeService::BRAVE_THEME_TYPE_DEFAULT; | ||
|
||
if (theme == "Light") | ||
return BraveThemeService::BRAVE_THEME_TYPE_LIGHT; | ||
|
||
if (theme == "Dark") | ||
return BraveThemeService::BRAVE_THEME_TYPE_DARK; | ||
|
||
NOTREACHED(); | ||
return BraveThemeService::BRAVE_THEME_TYPE_DEFAULT; | ||
} | ||
|
||
std::string GetStringFromBraveThemeType( | ||
BraveThemeService::BraveThemeType theme) { | ||
switch (theme) { | ||
case BraveThemeService::BRAVE_THEME_TYPE_DEFAULT: | ||
return "Default"; | ||
case BraveThemeService::BRAVE_THEME_TYPE_LIGHT: | ||
return "Light"; | ||
case BraveThemeService::BRAVE_THEME_TYPE_DARK: | ||
return "Dark"; | ||
default: | ||
NOTREACHED(); | ||
} | ||
} | ||
} // namespace | ||
|
||
void BraveAppearanceHandler::RegisterMessages() { | ||
profile_ = Profile::FromWebUI(web_ui()); | ||
|
||
web_ui()->RegisterMessageCallback( | ||
"getBraveThemeType", | ||
base::BindRepeating(&BraveAppearanceHandler::GetBraveThemeType, | ||
base::Unretained(this))); | ||
web_ui()->RegisterMessageCallback( | ||
"setBraveThemeType", | ||
base::BindRepeating(&BraveAppearanceHandler::SetBraveThemeType, | ||
base::Unretained(this))); | ||
} | ||
|
||
void BraveAppearanceHandler::SetBraveThemeType(const base::ListValue* args) { | ||
CHECK_EQ(args->GetSize(), 1U); | ||
CHECK(profile_); | ||
|
||
std::string theme; | ||
args->GetString(0, &theme); | ||
SetBraveThemeTypePref(profile_, GetBraveThemeTypeFromString(theme)); | ||
} | ||
|
||
void BraveAppearanceHandler::GetBraveThemeType(const base::ListValue* args) { | ||
CHECK_EQ(args->GetSize(), 1U); | ||
CHECK(profile_); | ||
|
||
AllowJavascript(); | ||
ResolveJavascriptCallback( | ||
args->GetList()[0].Clone(), | ||
base::Value(GetStringFromBraveThemeType( | ||
BraveThemeService::GetBraveThemeType(profile_)))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* 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_UI_WEBUI_SETTINGS_BRAVE_APPEARANCE_HANDLER_H_ | ||
#define BRAVE_BROWSER_UI_WEBUI_SETTINGS_BRAVE_APPEARANCE_HANDLER_H_ | ||
|
||
#include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h" | ||
|
||
class Profile; | ||
|
||
class BraveAppearanceHandler : public settings::SettingsPageUIHandler { | ||
public: | ||
BraveAppearanceHandler() = default; | ||
~BraveAppearanceHandler() override = default; | ||
|
||
private: | ||
// SettingsPageUIHandler overrides: | ||
void RegisterMessages() override; | ||
void OnJavascriptAllowed() override {} | ||
void OnJavascriptDisallowed() override {} | ||
|
||
void SetBraveThemeType(const base::ListValue* args); | ||
void GetBraveThemeType(const base::ListValue* args); | ||
|
||
Profile* profile_ = nullptr; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(BraveAppearanceHandler); | ||
}; | ||
|
||
#endif // BRAVE_BROWSER_UI_WEBUI_SETTINGS_BRAVE_APPEARANCE_HANDLER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
patches/chrome-browser-resources-settings-appearance_page-appearance_page.html.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
diff --git a/chrome/browser/resources/settings/appearance_page/appearance_page.html b/chrome/browser/resources/settings/appearance_page/appearance_page.html | ||
index 720d25d126a118315a08cef90d77d1fc78775254..b000205ff1ca4d4d62c53abffa93df237fc05756 100644 | ||
--- a/chrome/browser/resources/settings/appearance_page/appearance_page.html | ||
+++ b/chrome/browser/resources/settings/appearance_page/appearance_page.html | ||
@@ -19,6 +19,10 @@ | ||
<link rel="import" href="appearance_fonts_page.html"> | ||
<link rel="import" href="home_url_input.html"> | ||
|
||
+<if expr="not _google_chrome"> | ||
+<link rel="import" href="../brave_appearance_page/brave_appearance_page.html"> | ||
+</if> | ||
+ | ||
<dom-module id="settings-appearance-page"> | ||
<template> | ||
<style include="settings-shared md-select iron-flex"> | ||
@@ -102,6 +106,9 @@ | ||
</div> | ||
</if> | ||
</div> | ||
+ <if expr="not _google_chrome"> | ||
+ <settings-brave-appearance-page></settings-brave-appearance-page> | ||
+</if> | ||
<settings-toggle-button elide-label | ||
hidden="[[!pageVisibility.homeButton]]" | ||
pref="{{prefs.browser.show_home_button}}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters