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

Side by Side Diff: components/dom_distiller/core/reader_mode_preferences.cc

Issue 341563002: Theme Preferences for Distilled Pages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Implmented CSS Classes, rebased CSS, added Javascript for instantaneous changes Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/dom_distiller/core/reader_mode_preferences.h"
6
7 #include "base/observer_list.h"
8 #include "base/prefs/pref_service.h"
9 #include "components/pref_registry/pref_registry_syncable.h"
10
11 namespace {
12
13 // True if user prefers high-contrast (dark) appearance when in reader mode.
14 const char kThemePref[] = "dom_distiller.theme";
15
16 // Css class names - must agree with css/distilledpage.css.
nyquist 2014/06/26 20:39:58 s/Css/CSS/
smaslo 2014/06/27 18:33:17 I wasn't sure exactly what you meant by this comme
17 const char kHighContrastClassName[] = "highcontrast";
nyquist 2014/06/26 20:39:58 Could these move to the viewer.cc instead?
smaslo 2014/06/27 18:33:18 Done.
18 const char kNormalClassName[] = "normal";
19 const char kSepiaClassName[] = "sepia";
20
21 }
22
23 namespace dom_distiller {
24
25 ReaderModePrefs::ReaderModePrefs(PrefService* pref_service)
26 : pref_service_(pref_service) {
27 }
28
29 ReaderModePrefs::~ReaderModePrefs() {
30 }
31
32 // static
33 void ReaderModePrefs::RegisterProfilePrefs(
34 user_prefs::PrefRegistrySyncable* registry) {
35 registry->RegisterBooleanPref(kThemePref,
36 false,
37 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
38 }
39
40 void ReaderModePrefs::SetThemePref(Theme new_theme) {
41 pref_service_->SetInteger(kThemePref, new_theme);
42 NotifyOnChangeTheme();
43 }
44
45 void ReaderModePrefs::AddObserver(Observer* obs) {
46 observer_list_.AddObserver(obs);
47 }
48
49 void ReaderModePrefs::RemoveObserver(Observer* obs) {
50 observer_list_.RemoveObserver(obs);
51 }
52
53 void ReaderModePrefs::NotifyOnChangeTheme() {
54 FOR_EACH_OBSERVER(Observer, observer_list_, OnChangeTheme(this));
55 }
56
57 const char* ReaderModePrefs::GetBodyCssClass() {
58 if(GetThemePref() == (int) Theme::kHighContrast) {
nyquist 2014/06/26 20:39:58 Are these casts necessary?
smaslo 2014/06/27 18:33:17 Done.
59 return kHighContrastClassName;
60 }
61 else if (GetThemePref() == (int) Theme::kSepia) {
62 return kSepiaClassName;
63 }
64 else {
65 return kNormalClassName;
66 }
67 }
68
69 ReaderModePrefs::Theme ReaderModePrefs::GetThemePref() {
70 return (Theme) pref_service_->GetInteger(kThemePref);
71 }
72
73 } // namespace dom_distiller
nyquist 2014/06/26 20:39:58 Nit: Is this file missing a newline at the end now
smaslo 2014/06/27 18:33:17 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698