OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authros. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/dom_distiller/core/reader_mode_preferences.h" | |
6 | |
7 #include <string> | |
8 #include <vector> | |
9 | |
10 #include "base/prefs/pref_service.h" | |
11 #include "base/strings/string_util.h" | |
12 #include "components/dom_distiller/core/url_constants.h" | |
13 #include "components/pref_registry/pref_registry_syncable.h" | |
14 #include "grit/component_resources.h" | |
15 #include "ui/base/resource/resource_bundle.h" | |
16 | |
17 namespace prefs { | |
18 const char kHigh_Contrast_Pref[] = "reader_mode.high_contrast"; | |
19 } | |
20 | |
21 namespace dom_distiller { | |
22 | |
23 namespace { | |
24 const char WHITE[] = "#FFF"; | |
25 const char BLACK[] = "#000"; | |
26 } // namespace | |
27 | |
28 ReaderModePrefs::ReaderModePrefs(PrefService* current_pref_service) { | |
robliao
2014/06/17 18:01:49
Consistency: pref_service as a name should work fi
smaslo
2014/06/17 22:44:07
Done.
| |
29 DCHECK(current_pref_service); | |
30 ReaderModePrefs::pref_service = current_pref_service; | |
robliao
2014/06/17 18:01:49
Put this in a constructor initializer list.
http:/
smaslo
2014/06/17 22:44:08
Done.
| |
31 } | |
32 | |
robliao
2014/06/17 18:01:49
Remove extra line.
smaslo
2014/06/17 22:44:08
Done.
| |
33 | |
34 std::string ReaderModePrefs::ReplaceCSSTemplateValues() { | |
robliao
2014/06/17 18:01:50
This should really go into the viewer code near Ge
smaslo
2014/06/17 22:44:07
Done.
| |
35 std::vector<std::string> substitutions; | |
36 substitutions.push_back(GetBodyInsertionText()); | |
37 base::StringPiece css_template = | |
38 ResourceBundle::GetSharedInstance().GetRawDataResource( | |
39 IDR_DISTILLER_CSS); | |
40 return ReplaceStringPlaceholders(css_template, substitutions, NULL); | |
41 } | |
42 | |
43 void ReaderModePrefs::OnChangeHighContrast(bool new_value) { | |
44 pref_service->SetBoolean(prefs::kHigh_Contrast_Pref, new_value); | |
45 } | |
46 | |
47 void ReaderModePrefs::RegisterProfilePrefs( | |
48 user_prefs::PrefRegistrySyncable* registry) { | |
49 registry->RegisterBooleanPref(prefs::kHigh_Contrast_Pref, | |
50 false, | |
51 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | |
52 } | |
53 | |
54 bool ReaderModePrefs::GetHighContrastPref() { | |
55 return pref_service->GetBoolean(prefs::kHigh_Contrast_Pref); | |
56 } | |
57 | |
58 std::string ReaderModePrefs::GetBodyInsertionText() { | |
59 if (pref_service->GetBoolean(prefs::kHigh_Contrast_Pref)) { | |
60 std::string body_insertion_text = "background-color: "; | |
61 body_insertion_text += BLACK; | |
62 body_insertion_text += ";\ncolor: "; | |
63 body_insertion_text += WHITE; | |
64 body_insertion_text += ";"; | |
65 return body_insertion_text; | |
66 } | |
67 else { | |
68 std::string body_insertion_text = "background-color: "; | |
69 body_insertion_text += WHITE; | |
70 body_insertion_text += ";\ncolor: "; | |
71 body_insertion_text += BLACK; | |
72 body_insertion_text += ";"; | |
73 return body_insertion_text; | |
74 } | |
75 } | |
76 | |
77 } // namespace dom_distiller | |
robliao
2014/06/17 18:01:49
One more space required between } and //
smaslo
2014/06/17 22:44:07
Done.
| |
78 | |
OLD | NEW |