-
Notifications
You must be signed in to change notification settings - Fork 873
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update show bookmarks setting (#15577)
- Loading branch information
1 parent
c1a1559
commit b01395c
Showing
38 changed files
with
1,177 additions
and
25 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
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
21 changes: 21 additions & 0 deletions
21
browser/resources/settings/brave_appearance_page/bookmark_bar.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,21 @@ | ||
<style include="settings-shared iron-flex"> | ||
.settings-box.bottom-border { | ||
border-bottom: var(--cr-separator-line); | ||
border-top: none; | ||
} | ||
</style> | ||
<div class="settings-box bottom-border"> | ||
<div class="flex" id="labelWrapper" aria-hidden="true"> | ||
<div class="label">$i18n{appearanceSettingsBookmarBar}</div> | ||
<div class="secondary label" id="sub-label"> | ||
<span id="sub-label-text" aria-hidden="true"> | ||
[[bookmarkBarShowEnabledLabel_]] | ||
</span> | ||
</div> | ||
</div> | ||
<settings-dropdown-menu | ||
pref="[[bookmarkBarStatePref_]]" | ||
on-settings-control-change="onShowOptionChanged_" | ||
menu-options="[[bookmarkBarShowOptions_]]"> | ||
</settings-dropdown-menu> | ||
</div> |
144 changes: 144 additions & 0 deletions
144
browser/resources/settings/brave_appearance_page/bookmark_bar.ts
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,144 @@ | ||
// Copyright (c) 2022 The Brave Authors. All rights reserved. | ||
// 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 https://mozilla.org/MPL/2.0/. | ||
|
||
import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js' | ||
import {I18nMixin, I18nMixinInterface} from 'chrome://resources/cr_elements/i18n_mixin.js' | ||
import {PrefsMixin, PrefsMixinInterface} from '../prefs/prefs_mixin.js' | ||
import '../settings_shared.css.js' | ||
import '../settings_vars.css.js' | ||
import {getTemplate} from './bookmark_bar.html.js' | ||
|
||
const SettingsBraveAppearanceBookmarkBarElementBase = | ||
PrefsMixin(I18nMixin(PolymerElement)) as { | ||
new (): PolymerElement & I18nMixinInterface & PrefsMixinInterface | ||
} | ||
|
||
enum BookmarkBarState { | ||
ALWAYS = 0, | ||
NONE = 1, | ||
NTP = 2, | ||
} | ||
|
||
const kAlwaysShowBookmarBarPrefName = 'brave.always_show_bookmark_bar_on_ntp' | ||
const kShowOnAllTabsPrefName = 'bookmark_bar.show_on_all_tabs' | ||
|
||
/** | ||
* 'settings-brave-appearance-bookmark-bar' is the settings page area containing | ||
* brave's bookmark bar visibility settings in appearance settings. | ||
*/ | ||
export class SettingsBraveAppearanceBookmarkBarElement | ||
extends SettingsBraveAppearanceBookmarkBarElementBase { | ||
static get is() { | ||
return 'settings-brave-appearance-bookmark-bar' | ||
} | ||
|
||
static get template() { | ||
return getTemplate() | ||
} | ||
|
||
static get properties() { | ||
return { | ||
/** @private {chrome.settingsPrivate.PrefType} */ | ||
bookmarkBarStatePref_: { | ||
key: '', | ||
type: Object, | ||
value() { | ||
return { | ||
key: '', | ||
type: chrome.settingsPrivate.PrefType.NUMBER, | ||
value: BookmarkBarState.NTP | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
bookmarkBarStatePref_: chrome.settingsPrivate.PrefObject | ||
|
||
private bookmarkBarShowOptions_ = [ | ||
{ | ||
value: BookmarkBarState.ALWAYS, | ||
name: this.i18n('appearanceSettingsBookmarBarAlways') | ||
}, | ||
{ | ||
value: BookmarkBarState.NONE, | ||
name: this.i18n('appearanceSettingsBookmarBarNever') | ||
}, | ||
{ | ||
value: BookmarkBarState.NTP, | ||
name: this.i18n('appearanceSettingsBookmarBarNTP') | ||
} | ||
] | ||
private bookmarkBarShowEnabledLabel_: string | ||
|
||
static get observers() { | ||
return [ | ||
'onPrefsChanged_(prefs.bookmark_bar.show_on_all_tabs.value,' + | ||
' prefs.brave.always_show_bookmark_bar_on_ntp.value)' | ||
] | ||
} | ||
|
||
override ready() { | ||
super.ready() | ||
window.addEventListener('load', this.onLoad_.bind(this)); | ||
} | ||
|
||
private onLoad_() { | ||
this.setControlValueFromPrefs() | ||
} | ||
|
||
private getBookmarkBarStateFromPrefs(): BookmarkBarState { | ||
if (this.getPref(kShowOnAllTabsPrefName).value) | ||
return BookmarkBarState.ALWAYS | ||
|
||
if (this.getPref(kAlwaysShowBookmarBarPrefName).value) | ||
return BookmarkBarState.NTP | ||
return BookmarkBarState.NONE | ||
} | ||
|
||
private saveBookmarkBarStateToPrefs(state: BookmarkBarState) { | ||
if (state === BookmarkBarState.ALWAYS) { | ||
this.setPrefValue(kShowOnAllTabsPrefName, true) | ||
} else if (state === BookmarkBarState.NTP) { | ||
this.setPrefValue(kShowOnAllTabsPrefName, false) | ||
this.setPrefValue(kAlwaysShowBookmarBarPrefName, true) | ||
} else { | ||
this.setPrefValue(kShowOnAllTabsPrefName, false) | ||
this.setPrefValue(kAlwaysShowBookmarBarPrefName, false) | ||
} | ||
} | ||
private setControlValueFromPrefs() { | ||
const state = this.getBookmarkBarStateFromPrefs() | ||
if (this.bookmarkBarStatePref_.value === state) | ||
return | ||
this.bookmarkBarStatePref_ = { | ||
key: '', | ||
type: chrome.settingsPrivate.PrefType.NUMBER, | ||
value: state | ||
}; | ||
} | ||
private onPrefsChanged_() { | ||
this.setControlValueFromPrefs() | ||
} | ||
private onShowOptionChanged_() { | ||
const state = this.bookmarkBarStatePref_.value | ||
if (state === BookmarkBarState.ALWAYS) { | ||
this.bookmarkBarShowEnabledLabel_ = | ||
this.i18n('appearanceSettingsBookmarBarAlwaysDesc') | ||
} else if (state === BookmarkBarState.NTP) { | ||
this.bookmarkBarShowEnabledLabel_ = | ||
this.i18n('appearanceSettingsBookmarBarNTPDesc') | ||
} else { | ||
this.bookmarkBarShowEnabledLabel_ = | ||
this.i18n('appearanceSettingsBookmarBarNeverDesc') | ||
} | ||
|
||
this.saveBookmarkBarStateToPrefs(this.bookmarkBarStatePref_.value) | ||
} | ||
|
||
} | ||
|
||
customElements.define(SettingsBraveAppearanceBookmarkBarElement.is, | ||
SettingsBraveAppearanceBookmarkBarElement) |
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
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,39 @@ | ||
/* Copyright (c) 2023 The Brave Authors. All rights reserved. | ||
* 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 https://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/browser/ui/bookmark/bookmark_helper.h" | ||
|
||
#include "brave/components/constants/pref_names.h" | ||
#include "components/bookmarks/common/bookmark_pref_names.h" | ||
#include "components/prefs/pref_service.h" | ||
|
||
namespace brave { | ||
|
||
BookmarkBarState GetBookmarkBarState(PrefService* prefs) { | ||
// kShowBookmarkBar has higher priority and the bookmark bar is shown always. | ||
if (prefs->GetBoolean(bookmarks::prefs::kShowBookmarkBar)) | ||
return BookmarkBarState::kAlways; | ||
// kShowBookmarkBar is false, kAlwaysShowBookmarkBarOnNTP is true | ||
// -> the bookmark bar is shown only for NTP. | ||
if (prefs->GetBoolean(kAlwaysShowBookmarkBarOnNTP)) | ||
return BookmarkBarState::kNtp; | ||
// NEVER show the bookmark bar. | ||
return BookmarkBarState::kNever; | ||
} | ||
|
||
void SetBookmarkState(BookmarkBarState state, PrefService* prefs) { | ||
if (state == BookmarkBarState::kAlways) { | ||
prefs->SetBoolean(bookmarks::prefs::kShowBookmarkBar, true); | ||
prefs->SetBoolean(kAlwaysShowBookmarkBarOnNTP, false); | ||
} else if (state == BookmarkBarState::kNtp) { | ||
prefs->SetBoolean(bookmarks::prefs::kShowBookmarkBar, false); | ||
prefs->SetBoolean(kAlwaysShowBookmarkBarOnNTP, true); | ||
} else { | ||
prefs->SetBoolean(bookmarks::prefs::kShowBookmarkBar, false); | ||
prefs->SetBoolean(kAlwaysShowBookmarkBarOnNTP, false); | ||
} | ||
} | ||
|
||
} // namespace brave |
Oops, something went wrong.