-
Notifications
You must be signed in to change notification settings - Fork 920
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
Changes from 7 commits
8d4c72b
30a7d4e
bc3599a
8f813a5
e34f448
aa9bb03
122da45
b921e63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,10 @@ | |
#include "base/bind.h" | ||
#include "base/feature_list.h" | ||
#include "base/strings/string_util.h" | ||
#include "base/strings/utf_string_conversions.h" | ||
#include "brave/browser/brave_browser_process.h" | ||
#include "brave/browser/speedreader/speedreader_service_factory.h" | ||
#include "brave/browser/themes/brave_dark_mode_utils.h" | ||
#include "brave/browser/ui/brave_browser_window.h" | ||
#include "brave/browser/ui/speedreader/speedreader_bubble_view.h" | ||
#include "brave/components/l10n/common/locale_util.h" | ||
|
@@ -258,6 +260,52 @@ void SpeedreaderTabHelper::OnShowOriginalPage() { | |
ReloadContents(); | ||
} | ||
|
||
void SpeedreaderTabHelper::SetTheme(Theme theme) { | ||
auto* speedreader_service = | ||
SpeedreaderServiceFactory::GetForProfile(GetProfile()); | ||
if (!speedreader_service) | ||
return; | ||
|
||
if (speedreader_service->GetTheme() == theme) | ||
return; | ||
|
||
constexpr const char16_t kSetTheme[] = | ||
uR"js( | ||
(function() { | ||
const theme = '$1' | ||
if (theme == '') { | ||
document.documentElement.removeAttribute('data-theme') | ||
} else { | ||
document.documentElement.setAttribute('data-theme', theme) | ||
} | ||
})(); | ||
)js"; | ||
|
||
speedreader_service->SetTheme(theme); | ||
|
||
const auto script = base::ReplaceStringPlaceholders( | ||
kSetTheme, base::UTF8ToUTF16(speedreader_service->GetThemeName()), | ||
nullptr); | ||
|
||
web_contents()->GetPrimaryMainFrame()->ExecuteJavaScriptInIsolatedWorld( | ||
script, base::DoNothing(), kIsolatedWorldId); | ||
} | ||
|
||
Theme SpeedreaderTabHelper::GetTheme() { | ||
const Theme theme = | ||
SpeedreaderServiceFactory::GetForProfile(GetProfile())->GetTheme(); | ||
if (theme == Theme::kNone) { | ||
switch (dark_mode::GetActiveBraveDarkModeType()) { | ||
case dark_mode::BraveDarkModeType::BRAVE_DARK_MODE_TYPE_DARK: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. // DEFAULT type acts as two ways depends on system theme mode. GetActiveBraveDarkModeType never returns default. |
||
return Theme::kDark; | ||
case dark_mode::BraveDarkModeType::BRAVE_DARK_MODE_TYPE_DEFAULT: | ||
case dark_mode::BraveDarkModeType::BRAVE_DARK_MODE_TYPE_LIGHT: | ||
return Theme::kLight; | ||
} | ||
} | ||
return theme; | ||
} | ||
|
||
void SpeedreaderTabHelper::ClearPersistedData() { | ||
if (auto* entry = web_contents()->GetController().GetLastCommittedEntry()) { | ||
SpeedreaderExtendedInfoHandler::ClearPersistedData(entry); | ||
|
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.
not used
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.
used in line 744