| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/chrome_page_zoom.h" | 5 #include "chrome/browser/chrome_page_zoom.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 | 58 |
| 59 std::vector<double> PresetZoomFactors(double custom_factor) { | 59 std::vector<double> PresetZoomFactors(double custom_factor) { |
| 60 return PresetZoomValues(PAGE_ZOOM_VALUE_TYPE_FACTOR, custom_factor); | 60 return PresetZoomValues(PAGE_ZOOM_VALUE_TYPE_FACTOR, custom_factor); |
| 61 } | 61 } |
| 62 | 62 |
| 63 std::vector<double> PresetZoomLevels(double custom_level) { | 63 std::vector<double> PresetZoomLevels(double custom_level) { |
| 64 return PresetZoomValues(PAGE_ZOOM_VALUE_TYPE_LEVEL, custom_level); | 64 return PresetZoomValues(PAGE_ZOOM_VALUE_TYPE_LEVEL, custom_level); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void Zoom(content::WebContents* web_contents, content::PageZoom zoom) { | 67 void Zoom(content::WebContents* web_contents, content::PageZoom zoom) { |
| 68 content::RenderViewHost* host = web_contents->GetRenderViewHost(); | |
| 69 double current_zoom_level = web_contents->GetZoomLevel(); | 68 double current_zoom_level = web_contents->GetZoomLevel(); |
| 70 double default_zoom_level = | 69 double default_zoom_level = |
| 71 Profile::FromBrowserContext(web_contents->GetBrowserContext())-> | 70 Profile::FromBrowserContext(web_contents->GetBrowserContext())-> |
| 72 GetPrefs()->GetDouble(prefs::kDefaultZoomLevel); | 71 GetPrefs()->GetDouble(prefs::kDefaultZoomLevel); |
| 73 | 72 |
| 74 if (zoom == content::PAGE_ZOOM_RESET) { | 73 if (zoom == content::PAGE_ZOOM_RESET) { |
| 75 host->SetZoomLevel(default_zoom_level); | 74 web_contents->SetZoomLevel(default_zoom_level); |
| 76 content::RecordAction(UserMetricsAction("ZoomNormal")); | 75 content::RecordAction(UserMetricsAction("ZoomNormal")); |
| 77 return; | 76 return; |
| 78 } | 77 } |
| 79 | 78 |
| 80 // Generate a vector of zoom levels from an array of known presets along with | 79 // Generate a vector of zoom levels from an array of known presets along with |
| 81 // the default level added if necessary. | 80 // the default level added if necessary. |
| 82 std::vector<double> zoom_levels = PresetZoomLevels(default_zoom_level); | 81 std::vector<double> zoom_levels = PresetZoomLevels(default_zoom_level); |
| 83 | 82 |
| 84 if (zoom == content::PAGE_ZOOM_OUT) { | 83 if (zoom == content::PAGE_ZOOM_OUT) { |
| 85 // Iterate through the zoom levels in reverse order to find the next | 84 // Iterate through the zoom levels in reverse order to find the next |
| 86 // lower level based on the current zoom level for this page. | 85 // lower level based on the current zoom level for this page. |
| 87 for (std::vector<double>::reverse_iterator i = zoom_levels.rbegin(); | 86 for (std::vector<double>::reverse_iterator i = zoom_levels.rbegin(); |
| 88 i != zoom_levels.rend(); ++i) { | 87 i != zoom_levels.rend(); ++i) { |
| 89 double zoom_level = *i; | 88 double zoom_level = *i; |
| 90 if (content::ZoomValuesEqual(zoom_level, current_zoom_level)) | 89 if (content::ZoomValuesEqual(zoom_level, current_zoom_level)) |
| 91 continue; | 90 continue; |
| 92 if (zoom_level < current_zoom_level) { | 91 if (zoom_level < current_zoom_level) { |
| 93 host->SetZoomLevel(zoom_level); | 92 web_contents->SetZoomLevel(zoom_level); |
| 94 content::RecordAction(UserMetricsAction("ZoomMinus")); | 93 content::RecordAction(UserMetricsAction("ZoomMinus")); |
| 95 return; | 94 return; |
| 96 } | 95 } |
| 97 content::RecordAction(UserMetricsAction("ZoomMinus_AtMinimum")); | 96 content::RecordAction(UserMetricsAction("ZoomMinus_AtMinimum")); |
| 98 } | 97 } |
| 99 } else { | 98 } else { |
| 100 // Iterate through the zoom levels in normal order to find the next | 99 // Iterate through the zoom levels in normal order to find the next |
| 101 // higher level based on the current zoom level for this page. | 100 // higher level based on the current zoom level for this page. |
| 102 for (std::vector<double>::const_iterator i = zoom_levels.begin(); | 101 for (std::vector<double>::const_iterator i = zoom_levels.begin(); |
| 103 i != zoom_levels.end(); ++i) { | 102 i != zoom_levels.end(); ++i) { |
| 104 double zoom_level = *i; | 103 double zoom_level = *i; |
| 105 if (content::ZoomValuesEqual(zoom_level, current_zoom_level)) | 104 if (content::ZoomValuesEqual(zoom_level, current_zoom_level)) |
| 106 continue; | 105 continue; |
| 107 if (zoom_level > current_zoom_level) { | 106 if (zoom_level > current_zoom_level) { |
| 108 host->SetZoomLevel(zoom_level); | 107 web_contents->SetZoomLevel(zoom_level); |
| 109 content::RecordAction(UserMetricsAction("ZoomPlus")); | 108 content::RecordAction(UserMetricsAction("ZoomPlus")); |
| 110 return; | 109 return; |
| 111 } | 110 } |
| 112 } | 111 } |
| 113 content::RecordAction(UserMetricsAction("ZoomPlus_AtMaximum")); | 112 content::RecordAction(UserMetricsAction("ZoomPlus_AtMaximum")); |
| 114 } | 113 } |
| 115 } | 114 } |
| 116 | 115 |
| 117 } // namespace chrome_page_zoom | 116 } // namespace chrome_page_zoom |
| OLD | NEW |