-
Notifications
You must be signed in to change notification settings - Fork 887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update show bookmarks setting #15577
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm a bit outdated, so don't really know what is the current convention - put tests into smaller BUILD.gn`s or continue stockpiling them in brave/test/BUILD.gn ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something wrong here?