OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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 "base/observer_list.h" |
| 6 #include "base/prefs/pref_change_registrar.h" |
| 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/values.h" |
| 9 #include "chrome/browser/accessibility/font_size_prefs.h" |
| 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/profiles/profile_android.h" |
| 12 #include "chrome/browser/profiles/profile_manager.h" |
| 13 #include "chrome/common/pref_names.h" |
| 14 |
| 15 FontSizePrefs::FontSizePrefs(Profile* profile) { |
| 16 pref_service_ = profile->GetPrefs(); |
| 17 pref_change_registrar_.reset(new PrefChangeRegistrar); |
| 18 pref_change_registrar_->Init(pref_service_); |
| 19 pref_change_registrar_->Add( |
| 20 prefs::kWebKitFontScaleFactor, |
| 21 base::Bind(&FontSizePrefs::OnFontScaleFactorPrefsChanged, |
| 22 base::Unretained(this))); |
| 23 pref_change_registrar_->Add( |
| 24 prefs::kWebKitForceEnableZoom, |
| 25 base::Bind(&FontSizePrefs::OnForceEnableZoomPrefsChanged, |
| 26 base::Unretained(this))); |
| 27 } |
| 28 |
| 29 FontSizePrefs::~FontSizePrefs() { |
| 30 } |
| 31 |
| 32 void FontSizePrefs::Destroy() { |
| 33 delete this; |
| 34 } |
| 35 |
| 36 void FontSizePrefs::SetFontScaleFactor(float font) { |
| 37 pref_service_->SetDouble(prefs::kWebKitFontScaleFactor, |
| 38 static_cast<double>(font)); |
| 39 } |
| 40 |
| 41 float FontSizePrefs::GetFontScaleFactor() { |
| 42 return pref_service_->GetDouble(prefs::kWebKitFontScaleFactor); |
| 43 } |
| 44 |
| 45 void FontSizePrefs::OnFontScaleFactorPrefsChanged() { |
| 46 FOR_EACH_OBSERVER( |
| 47 Observer, observers_, OnChangeFontSize(GetFontScaleFactor())); |
| 48 } |
| 49 |
| 50 void FontSizePrefs::AddObserver(Observer* obs) { |
| 51 observers_.AddObserver(obs); |
| 52 } |
| 53 |
| 54 void FontSizePrefs::RemoveObserver(Observer* obs) { |
| 55 observers_.RemoveObserver(obs); |
| 56 } |
| 57 |
| 58 void FontSizePrefs::SetForceEnableZoom(bool enabled) { |
| 59 pref_service_->SetBoolean(prefs::kWebKitForceEnableZoom, enabled); |
| 60 } |
| 61 |
| 62 bool FontSizePrefs::GetForceEnableZoom() { |
| 63 return pref_service_->GetBoolean(prefs::kWebKitForceEnableZoom); |
| 64 } |
| 65 |
| 66 void FontSizePrefs::OnForceEnableZoomPrefsChanged() { |
| 67 FOR_EACH_OBSERVER( |
| 68 Observer, observers_, OnChangeForceEnableZoom(GetForceEnableZoom())); |
| 69 } |
OLD | NEW |