Chromium Code Reviews| Index: components/dom_distiller/core/reader_mode_preferences.cc |
| diff --git a/components/dom_distiller/core/reader_mode_preferences.cc b/components/dom_distiller/core/reader_mode_preferences.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..84e33562905485516ed818c3b58f7f7c4faeb100 |
| --- /dev/null |
| +++ b/components/dom_distiller/core/reader_mode_preferences.cc |
| @@ -0,0 +1,73 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/dom_distiller/core/reader_mode_preferences.h" |
| + |
| +#include "base/observer_list.h" |
| +#include "base/prefs/pref_service.h" |
| +#include "components/pref_registry/pref_registry_syncable.h" |
| + |
| +namespace { |
| + |
| +// True if user prefers high-contrast (dark) appearance when in reader mode. |
| +const char kThemePref[] = "dom_distiller.theme"; |
| + |
| +// 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
|
| +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.
|
| +const char kNormalClassName[] = "normal"; |
| +const char kSepiaClassName[] = "sepia"; |
| + |
| +} |
| + |
| +namespace dom_distiller { |
| + |
| +ReaderModePrefs::ReaderModePrefs(PrefService* pref_service) |
| + : pref_service_(pref_service) { |
| +} |
| + |
| +ReaderModePrefs::~ReaderModePrefs() { |
| +} |
| + |
| +// static |
| +void ReaderModePrefs::RegisterProfilePrefs( |
| + user_prefs::PrefRegistrySyncable* registry) { |
| + registry->RegisterBooleanPref(kThemePref, |
| + false, |
| + user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| +} |
| + |
| +void ReaderModePrefs::SetThemePref(Theme new_theme) { |
| + pref_service_->SetInteger(kThemePref, new_theme); |
| + NotifyOnChangeTheme(); |
| +} |
| + |
| +void ReaderModePrefs::AddObserver(Observer* obs) { |
| + observer_list_.AddObserver(obs); |
| +} |
| + |
| +void ReaderModePrefs::RemoveObserver(Observer* obs) { |
| + observer_list_.RemoveObserver(obs); |
| +} |
| + |
| +void ReaderModePrefs::NotifyOnChangeTheme() { |
| + FOR_EACH_OBSERVER(Observer, observer_list_, OnChangeTheme(this)); |
| +} |
| + |
| +const char* ReaderModePrefs::GetBodyCssClass() { |
| + if(GetThemePref() == (int) Theme::kHighContrast) { |
|
nyquist
2014/06/26 20:39:58
Are these casts necessary?
smaslo
2014/06/27 18:33:17
Done.
|
| + return kHighContrastClassName; |
| + } |
| + else if (GetThemePref() == (int) Theme::kSepia) { |
| + return kSepiaClassName; |
| + } |
| + else { |
| + return kNormalClassName; |
| + } |
| +} |
| + |
| +ReaderModePrefs::Theme ReaderModePrefs::GetThemePref() { |
| + return (Theme) pref_service_->GetInteger(kThemePref); |
| +} |
| + |
| +} // 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.
|