Skip to content
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

Added theme change support in speedreader. #14307

Merged
merged 8 commits into from
Aug 2, 2022
Merged

Added theme change support in speedreader. #14307

merged 8 commits into from
Aug 2, 2022

Conversation

boocmp
Copy link
Contributor

@boocmp boocmp commented Jul 23, 2022

Resolves brave/brave-browser#23447

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally: npm run test -- brave_browser_tests, npm run test -- brave_unit_tests, npm run lint, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

NOTE: Downloadable component isn't updated yet. So to check this PR you should use built-in css stylesheet.
Make sure the component with id 'jicbkmdloagakknpihibphagfckhjdih' is removed from the profile before running browser for testing.

  1. Select some mode in Appearance->Brave Colors Settings.
  2. Navigate to the speedreadable page (f.e. https://www.bbc.com/news/business-58559179)
  3. Check mode corresponds to the selected in 1
  4. Open DevTools js console
  5. Paste document.documentElement.setAttribute('data-theme', 'dark') <- 'dark' or 'light' or 'sepia' should change mode.
  6. Paste document.documentElement.removeAttribute('data-theme') should return mode to the selected in 1.

NOTE: If something goes wrong, check component 'jicbkmdloagakknpihibphagfckhjdih' is not downloaded.

@boocmp boocmp requested a review from iefremov as a code owner July 23, 2022 04:46
@github-actions github-actions bot added the CI/storybook-url Deploy storybook and provide a unique URL for each build label Jul 23, 2022
@boocmp boocmp requested a review from nullhook July 23, 2022 04:46
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@@ -82,6 +87,7 @@ a[href] {
#article {
text-rendering: optimizeLegibility;
font-family: "Georgia", "Times New Roman", Times, serif;
user-select: unset;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we disabling user's ability to select text in the article?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took the entire speedreader-desktop.css file from the downloadable components. I don't know why :/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UPD: This rule doesn't disable text selection. It should be 'none' to disable, am i wrong ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, right. still not sure which value it's unsetting from or why it's needed

@@ -281,6 +282,11 @@ pub fn extract_dom<S: ::std::hash::BuildHasher>(
let title_blob = format!("<title>{}</title>", &meta.title);
content = title_blob + &content;
}

if let Some(theme) = theme {
content = format!("<html theme-data=\"{}\">", theme) + &content + "</html>";
Copy link
Contributor

@nullhook nullhook Jul 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

custom attributes are prefixed with data-*

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

std::string GetSystemTheme();
void SetTheme(Theme theme);
Theme GetTheme();
std::string GetThemeName();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need ::GetThemeName here again? We're probably using the service method or is this a left over?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, should be deleted.

@@ -11,6 +11,14 @@ class HostContentSettingsMap;

namespace speedreader {

// Enum is used in prefs. Be careful when changing or extending.
enum class Theme {
kDefault = 0, // Use browser's theme
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be kNone which implies the user hasn't set a theme.

case Theme::kDark:
return "dark";
}
NOTREACHED();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why NOTREACHED and not a default: switch case? a default switch case will always fallback

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch (s) {
  // cases
  default: return {};
}
// nothing needed here 

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@boocmp boocmp force-pushed the issues/23447 branch 2 times, most recently from 8f632cb to 137bd35 Compare July 27, 2022 05:31
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@@ -291,7 +291,7 @@ void SpeedreaderTabHelper::SetTheme(Theme theme) {
Theme SpeedreaderTabHelper::GetTheme() {
const Theme theme =
SpeedreaderServiceFactory::GetForProfile(GetProfile())->GetTheme();
if (theme == Theme::kDefault) {
if (theme == Theme::kNone) {
switch (dark_mode::GetActiveBraveDarkModeType()) {
case dark_mode::BraveDarkModeType::BRAVE_DARK_MODE_TYPE_DARK:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is ::BRAVE_DARK_MODE_TYPE_DEFAULT ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// DEFAULT type acts as two ways depends on system theme mode.
// If system dark mode is not supported, we override it with channel based
// policy. In this case, user can see dark or light option in settings.
// Otherwise, it acts like system dark mode mode. It respects system's dark
// mode. In this case, user can see all three options in theme settings.

GetActiveBraveDarkModeType never returns default.

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@@ -7,6 +7,7 @@

#include "base/feature_list.h"
#include "base/metrics/histogram_macros.h"
#include "base/notreached.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not used

#include "brave/browser/speedreader/speedreader_tab_helper.h"
#include "brave/components/speedreader/speedreader_throttle.h"
#include "brave/components/speedreader/speedreader_util.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not used

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

used in line 744

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@boocmp boocmp requested a review from nullhook August 1, 2022 11:14
Copy link
Contributor

@nullhook nullhook left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@boocmp boocmp merged commit a9d5f12 into master Aug 2, 2022
@boocmp boocmp deleted the issues/23447 branch August 2, 2022 08:45
@github-actions github-actions bot added this to the 1.44.x - Nightly milestone Aug 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/storybook-url Deploy storybook and provide a unique URL for each build
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[speedreader] Dark/Light theme support
4 participants