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

Side by Side 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: keep focus when useFontScaling() is called, add tests Created 5 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/dom_distiller/core/distilled_page_prefs.h" 5 #include "components/dom_distiller/core/distilled_page_prefs.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/observer_list.h" 10 #include "base/observer_list.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
13 #include "base/thread_task_runner_handle.h" 13 #include "base/thread_task_runner_handle.h"
14 #include "components/pref_registry/pref_registry_syncable.h" 14 #include "components/pref_registry/pref_registry_syncable.h"
15 15
16 namespace { 16 namespace {
17 17
18 // Path to the integer corresponding to user's preference theme. 18 // Path to the integer corresponding to user's preference theme.
19 const char kFontPref[] = "dom_distiller.font_family"; 19 const char kFontPref[] = "dom_distiller.font_family";
20 // Path to the integer corresponding to user's preference font family. 20 // Path to the integer corresponding to user's preference font family.
21 const char kThemePref[] = "dom_distiller.theme"; 21 const char kThemePref[] = "dom_distiller.theme";
22 // Path to the float corresponding to user's preference font scaling.
23 const char kFontScalePref[] = "dom_distiller.font_scale";
22 } 24 }
23 25
24 namespace dom_distiller { 26 namespace dom_distiller {
25 27
26 DistilledPagePrefs::DistilledPagePrefs(PrefService* pref_service) 28 DistilledPagePrefs::DistilledPagePrefs(PrefService* pref_service)
27 : pref_service_(pref_service), weak_ptr_factory_(this) { 29 : pref_service_(pref_service), weak_ptr_factory_(this) {
28 } 30 }
29 31
30 DistilledPagePrefs::~DistilledPagePrefs() { 32 DistilledPagePrefs::~DistilledPagePrefs() {
31 } 33 }
32 34
33 // static 35 // static
34 void DistilledPagePrefs::RegisterProfilePrefs( 36 void DistilledPagePrefs::RegisterProfilePrefs(
35 user_prefs::PrefRegistrySyncable* registry) { 37 user_prefs::PrefRegistrySyncable* registry) {
36 registry->RegisterIntegerPref( 38 registry->RegisterIntegerPref(
37 kThemePref, 39 kThemePref,
38 DistilledPagePrefs::LIGHT, 40 DistilledPagePrefs::LIGHT,
39 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 41 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
40 registry->RegisterIntegerPref( 42 registry->RegisterIntegerPref(
41 kFontPref, 43 kFontPref,
42 DistilledPagePrefs::SANS_SERIF, 44 DistilledPagePrefs::SANS_SERIF,
43 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 45 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
46 registry->RegisterDoublePref(
47 kFontScalePref,
48 1.0);
44 } 49 }
45 50
46 void DistilledPagePrefs::SetFontFamily( 51 void DistilledPagePrefs::SetFontFamily(
47 DistilledPagePrefs::FontFamily new_font_family) { 52 DistilledPagePrefs::FontFamily new_font_family) {
48 pref_service_->SetInteger(kFontPref, new_font_family); 53 pref_service_->SetInteger(kFontPref, new_font_family);
49 base::ThreadTaskRunnerHandle::Get()->PostTask( 54 base::ThreadTaskRunnerHandle::Get()->PostTask(
50 FROM_HERE, base::Bind(&DistilledPagePrefs::NotifyOnChangeFontFamily, 55 FROM_HERE, base::Bind(&DistilledPagePrefs::NotifyOnChangeFontFamily,
51 weak_ptr_factory_.GetWeakPtr(), new_font_family)); 56 weak_ptr_factory_.GetWeakPtr(), new_font_family));
52 } 57 }
53 58
(...skipping 19 matching lines...) Expand all
73 int theme = pref_service_->GetInteger(kThemePref); 78 int theme = pref_service_->GetInteger(kThemePref);
74 if (theme < 0 || theme >= DistilledPagePrefs::THEME_COUNT) { 79 if (theme < 0 || theme >= DistilledPagePrefs::THEME_COUNT) {
75 // Persisted data was incorrect, trying to clean it up by storing the 80 // Persisted data was incorrect, trying to clean it up by storing the
76 // default. 81 // default.
77 SetTheme(DistilledPagePrefs::LIGHT); 82 SetTheme(DistilledPagePrefs::LIGHT);
78 return DistilledPagePrefs::LIGHT; 83 return DistilledPagePrefs::LIGHT;
79 } 84 }
80 return static_cast<Theme>(theme); 85 return static_cast<Theme>(theme);
81 } 86 }
82 87
88 void DistilledPagePrefs::SetFontScaling(float scaling) {
89 pref_service_->SetDouble(kFontScalePref, scaling);
90 base::ThreadTaskRunnerHandle::Get()->PostTask(
91 FROM_HERE,
92 base::Bind(&DistilledPagePrefs::NotifyOnChangeFontScaling,
93 weak_ptr_factory_.GetWeakPtr(),
94 scaling));
95 }
96
97 float DistilledPagePrefs::GetFontScaling() {
98 float scaling = pref_service_->GetDouble(kFontScalePref);
99 if (scaling < 0.4 || scaling > 2.5) {
100 // Persisted data was incorrect, trying to clean it up by storing the
101 // default.
102 SetFontScaling(1.0);
103 return 1.0;
104 }
105 return scaling;
106 }
107
83 void DistilledPagePrefs::AddObserver(Observer* obs) { 108 void DistilledPagePrefs::AddObserver(Observer* obs) {
84 observers_.AddObserver(obs); 109 observers_.AddObserver(obs);
85 } 110 }
86 111
87 void DistilledPagePrefs::RemoveObserver(Observer* obs) { 112 void DistilledPagePrefs::RemoveObserver(Observer* obs) {
88 observers_.RemoveObserver(obs); 113 observers_.RemoveObserver(obs);
89 } 114 }
90 115
91 void DistilledPagePrefs::NotifyOnChangeFontFamily( 116 void DistilledPagePrefs::NotifyOnChangeFontFamily(
92 DistilledPagePrefs::FontFamily new_font_family) { 117 DistilledPagePrefs::FontFamily new_font_family) {
93 FOR_EACH_OBSERVER(Observer, observers_, OnChangeFontFamily(new_font_family)); 118 FOR_EACH_OBSERVER(Observer, observers_, OnChangeFontFamily(new_font_family));
94 } 119 }
95 120
96 void DistilledPagePrefs::NotifyOnChangeTheme( 121 void DistilledPagePrefs::NotifyOnChangeTheme(
97 DistilledPagePrefs::Theme new_theme) { 122 DistilledPagePrefs::Theme new_theme) {
98 FOR_EACH_OBSERVER(Observer, observers_, OnChangeTheme(new_theme)); 123 FOR_EACH_OBSERVER(Observer, observers_, OnChangeTheme(new_theme));
99 } 124 }
100 125
126 void DistilledPagePrefs::NotifyOnChangeFontScaling(
127 float scaling) {
128 FOR_EACH_OBSERVER(Observer, observers_, OnChangeFontScaling(scaling));
129 }
130
101 } // namespace dom_distiller 131 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698