Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <cmath> | 5 #include <cmath> |
| 6 | 6 |
| 7 #include "content/browser/host_zoom_map.h" | 7 #include "content/browser/host_zoom_map.h" |
| 8 | 8 |
| 9 #include "base/string_piece.h" | 9 #include "base/string_piece.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 host_zoom_levels_.clear(); | 55 host_zoom_levels_.clear(); |
| 56 const DictionaryValue* host_zoom_dictionary = | 56 const DictionaryValue* host_zoom_dictionary = |
| 57 profile_->GetPrefs()->GetDictionary(prefs::kPerHostZoomLevels); | 57 profile_->GetPrefs()->GetDictionary(prefs::kPerHostZoomLevels); |
| 58 // Careful: The returned value could be NULL if the pref has never been set. | 58 // Careful: The returned value could be NULL if the pref has never been set. |
| 59 if (host_zoom_dictionary != NULL) { | 59 if (host_zoom_dictionary != NULL) { |
| 60 for (DictionaryValue::key_iterator i(host_zoom_dictionary->begin_keys()); | 60 for (DictionaryValue::key_iterator i(host_zoom_dictionary->begin_keys()); |
| 61 i != host_zoom_dictionary->end_keys(); ++i) { | 61 i != host_zoom_dictionary->end_keys(); ++i) { |
| 62 const std::string& host(*i); | 62 const std::string& host(*i); |
| 63 double zoom_level = 0; | 63 double zoom_level = 0; |
| 64 | 64 |
| 65 bool success = host_zoom_dictionary->GetDoubleWithoutPathExpansion( | 65 // The data used to be stored as ints, so try that first. Note that |
| 66 host, &zoom_level); | 66 // GetDoubleWithoutPathExpansion supports both Integer and Double values. |
| 67 if (!success) { | 67 int int_zoom_level; |
| 68 // The data used to be stored as ints, so try that. | 68 bool success = host_zoom_dictionary->GetIntegerWithoutPathExpansion( |
| 69 int int_zoom_level; | 69 host, &int_zoom_level); |
| 70 success = host_zoom_dictionary->GetIntegerWithoutPathExpansion( | 70 if (success) { |
| 71 host, &int_zoom_level); | 71 zoom_level = static_cast<double>(int_zoom_level); |
| 72 if (success) { | 72 // Since the values were once stored as non-clamped, clamp now. |
| 73 zoom_level = static_cast<double>(int_zoom_level); | 73 double zoom_factor = WebView::zoomLevelToZoomFactor(zoom_level); |
| 74 // Since the values were once stored as non-clamped, clamp now. | 74 if (zoom_factor < WebView::minTextSizeMultiplier) { |
| 75 double zoom_factor = WebView::zoomLevelToZoomFactor(zoom_level); | 75 zoom_level = |
| 76 if (zoom_factor < WebView::minTextSizeMultiplier) { | 76 WebView::zoomFactorToZoomLevel(WebView::minTextSizeMultiplier); |
| 77 zoom_level = | 77 } else if (zoom_factor > WebView::maxTextSizeMultiplier) { |
| 78 WebView::zoomFactorToZoomLevel(WebView::minTextSizeMultiplier); | 78 zoom_level = |
| 79 } else if (zoom_factor > WebView::maxTextSizeMultiplier) { | 79 WebView::zoomFactorToZoomLevel(WebView::maxTextSizeMultiplier); |
| 80 zoom_level = | |
| 81 WebView::zoomFactorToZoomLevel(WebView::maxTextSizeMultiplier); | |
| 82 } | |
| 83 } | 80 } |
| 81 } else { | |
| 82 success = host_zoom_dictionary->GetDoubleWithoutPathExpansion( | |
|
jam
2011/05/02 16:17:04
why not only call GetDoubleWithoutPathExpansion?
Yusuke Sato
2011/05/04 14:10:10
Done. Removed the old code.
| |
| 83 host, &zoom_level); | |
| 84 } | 84 } |
| 85 DCHECK(success); | 85 DCHECK(success); |
| 86 host_zoom_levels_[host] = zoom_level; | 86 host_zoom_levels_[host] = zoom_level; |
| 87 } | 87 } |
| 88 } | 88 } |
| 89 } | 89 } |
| 90 | 90 |
| 91 // static | 91 // static |
| 92 void HostZoomMap::RegisterUserPrefs(PrefService* prefs) { | 92 void HostZoomMap::RegisterUserPrefs(PrefService* prefs) { |
| 93 prefs->RegisterDoublePref(prefs::kDefaultZoomLevel, 0.0); | 93 prefs->RegisterDoublePref(prefs::kDefaultZoomLevel, 0.0); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 break; | 237 break; |
| 238 } | 238 } |
| 239 default: | 239 default: |
| 240 NOTREACHED() << "Unexpected preference observed."; | 240 NOTREACHED() << "Unexpected preference observed."; |
| 241 } | 241 } |
| 242 } | 242 } |
| 243 | 243 |
| 244 HostZoomMap::~HostZoomMap() { | 244 HostZoomMap::~HostZoomMap() { |
| 245 Shutdown(); | 245 Shutdown(); |
| 246 } | 246 } |
| OLD | NEW |