Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(570)

Unified Diff: components/dom_distiller/core/distilled_page_prefs.cc

Issue 1225183002: Font size in DomDistiller prefs syncs with local scaling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge master again Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/dom_distiller/core/distilled_page_prefs.cc
diff --git a/components/dom_distiller/core/distilled_page_prefs.cc b/components/dom_distiller/core/distilled_page_prefs.cc
index fed24235060b6c23866c6f8e959ee938d2de0486..9a68ef8e9a2ef7f18ffd55ae060be1a253d71442 100644
--- a/components/dom_distiller/core/distilled_page_prefs.cc
+++ b/components/dom_distiller/core/distilled_page_prefs.cc
@@ -19,6 +19,8 @@ namespace {
const char kFontPref[] = "dom_distiller.font_family";
// Path to the integer corresponding to user's preference font family.
const char kThemePref[] = "dom_distiller.theme";
+// Path to the float corresponding to user's preference font scaling.
+const char kFontScalePref[] = "dom_distiller.font_scale";
}
namespace dom_distiller {
@@ -41,6 +43,9 @@ void DistilledPagePrefs::RegisterProfilePrefs(
kFontPref,
DistilledPagePrefs::SANS_SERIF,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
+ registry->RegisterDoublePref(
+ kFontScalePref,
+ 1.0);
}
void DistilledPagePrefs::SetFontFamily(
@@ -80,6 +85,26 @@ DistilledPagePrefs::Theme DistilledPagePrefs::GetTheme() {
return static_cast<Theme>(theme);
}
+void DistilledPagePrefs::SetFontScaling(float scaling) {
+ pref_service_->SetDouble(kFontScalePref, scaling);
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE,
+ base::Bind(&DistilledPagePrefs::NotifyOnChangeFontScaling,
+ weak_ptr_factory_.GetWeakPtr(),
+ scaling));
+}
+
+float DistilledPagePrefs::GetFontScaling() {
+ float scaling = pref_service_->GetDouble(kFontScalePref);
+ if (scaling < 0.4 || scaling > 2.5) {
+ // Persisted data was incorrect, trying to clean it up by storing the
+ // default.
+ SetFontScaling(1.0);
+ return 1.0;
+ }
+ return scaling;
+}
+
void DistilledPagePrefs::AddObserver(Observer* obs) {
observers_.AddObserver(obs);
}
@@ -98,4 +123,9 @@ void DistilledPagePrefs::NotifyOnChangeTheme(
FOR_EACH_OBSERVER(Observer, observers_, OnChangeTheme(new_theme));
}
+void DistilledPagePrefs::NotifyOnChangeFontScaling(
+ float scaling) {
+ FOR_EACH_OBSERVER(Observer, observers_, OnChangeFontScaling(scaling));
+}
+
} // namespace dom_distiller
« no previous file with comments | « components/dom_distiller/core/distilled_page_prefs.h ('k') | components/dom_distiller/core/distilled_page_prefs_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698