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" |
11 #include "chrome/browser/chrome_page_zoom_constants.h" | 11 #include "chrome/browser/chrome_page_zoom_constants.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 14 #include "content/public/browser/host_zoom_map.h" |
14 #include "content/public/browser/render_view_host.h" | 15 #include "content/public/browser/render_view_host.h" |
15 #include "content/public/browser/user_metrics.h" | 16 #include "content/public/browser/user_metrics.h" |
16 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
17 #include "content/public/common/page_zoom.h" | 18 #include "content/public/common/page_zoom.h" |
18 #include "content/public/common/renderer_preferences.h" | 19 #include "content/public/common/renderer_preferences.h" |
19 | 20 |
20 using base::UserMetricsAction; | 21 using base::UserMetricsAction; |
21 | 22 |
22 namespace chrome_page_zoom { | 23 namespace chrome_page_zoom { |
23 | 24 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 59 |
59 std::vector<double> PresetZoomFactors(double custom_factor) { | 60 std::vector<double> PresetZoomFactors(double custom_factor) { |
60 return PresetZoomValues(PAGE_ZOOM_VALUE_TYPE_FACTOR, custom_factor); | 61 return PresetZoomValues(PAGE_ZOOM_VALUE_TYPE_FACTOR, custom_factor); |
61 } | 62 } |
62 | 63 |
63 std::vector<double> PresetZoomLevels(double custom_level) { | 64 std::vector<double> PresetZoomLevels(double custom_level) { |
64 return PresetZoomValues(PAGE_ZOOM_VALUE_TYPE_LEVEL, custom_level); | 65 return PresetZoomValues(PAGE_ZOOM_VALUE_TYPE_LEVEL, custom_level); |
65 } | 66 } |
66 | 67 |
67 void Zoom(content::WebContents* web_contents, content::PageZoom zoom) { | 68 void Zoom(content::WebContents* web_contents, content::PageZoom zoom) { |
68 double current_zoom_level = web_contents->GetZoomLevel(); | 69 double current_zoom_level = content::HostZoomMap::GetZoomLevel(web_contents); |
69 double default_zoom_level = | 70 double default_zoom_level = |
70 Profile::FromBrowserContext(web_contents->GetBrowserContext())-> | 71 Profile::FromBrowserContext(web_contents->GetBrowserContext())-> |
71 GetPrefs()->GetDouble(prefs::kDefaultZoomLevel); | 72 GetPrefs()->GetDouble(prefs::kDefaultZoomLevel); |
72 | 73 |
73 if (zoom == content::PAGE_ZOOM_RESET) { | 74 if (zoom == content::PAGE_ZOOM_RESET) { |
74 web_contents->SetZoomLevel(default_zoom_level); | 75 content::HostZoomMap::SetZoomLevel(web_contents, default_zoom_level); |
75 content::RecordAction(UserMetricsAction("ZoomNormal")); | 76 content::RecordAction(UserMetricsAction("ZoomNormal")); |
76 return; | 77 return; |
77 } | 78 } |
78 | 79 |
79 // Generate a vector of zoom levels from an array of known presets along with | 80 // Generate a vector of zoom levels from an array of known presets along with |
80 // the default level added if necessary. | 81 // the default level added if necessary. |
81 std::vector<double> zoom_levels = PresetZoomLevels(default_zoom_level); | 82 std::vector<double> zoom_levels = PresetZoomLevels(default_zoom_level); |
82 | 83 |
83 if (zoom == content::PAGE_ZOOM_OUT) { | 84 if (zoom == content::PAGE_ZOOM_OUT) { |
84 // Iterate through the zoom levels in reverse order to find the next | 85 // Iterate through the zoom levels in reverse order to find the next |
85 // lower level based on the current zoom level for this page. | 86 // lower level based on the current zoom level for this page. |
86 for (std::vector<double>::reverse_iterator i = zoom_levels.rbegin(); | 87 for (std::vector<double>::reverse_iterator i = zoom_levels.rbegin(); |
87 i != zoom_levels.rend(); ++i) { | 88 i != zoom_levels.rend(); ++i) { |
88 double zoom_level = *i; | 89 double zoom_level = *i; |
89 if (content::ZoomValuesEqual(zoom_level, current_zoom_level)) | 90 if (content::ZoomValuesEqual(zoom_level, current_zoom_level)) |
90 continue; | 91 continue; |
91 if (zoom_level < current_zoom_level) { | 92 if (zoom_level < current_zoom_level) { |
92 web_contents->SetZoomLevel(zoom_level); | 93 content::HostZoomMap::SetZoomLevel(web_contents, zoom_level); |
93 content::RecordAction(UserMetricsAction("ZoomMinus")); | 94 content::RecordAction(UserMetricsAction("ZoomMinus")); |
94 return; | 95 return; |
95 } | 96 } |
96 content::RecordAction(UserMetricsAction("ZoomMinus_AtMinimum")); | 97 content::RecordAction(UserMetricsAction("ZoomMinus_AtMinimum")); |
97 } | 98 } |
98 } else { | 99 } else { |
99 // Iterate through the zoom levels in normal order to find the next | 100 // Iterate through the zoom levels in normal order to find the next |
100 // higher level based on the current zoom level for this page. | 101 // higher level based on the current zoom level for this page. |
101 for (std::vector<double>::const_iterator i = zoom_levels.begin(); | 102 for (std::vector<double>::const_iterator i = zoom_levels.begin(); |
102 i != zoom_levels.end(); ++i) { | 103 i != zoom_levels.end(); ++i) { |
103 double zoom_level = *i; | 104 double zoom_level = *i; |
104 if (content::ZoomValuesEqual(zoom_level, current_zoom_level)) | 105 if (content::ZoomValuesEqual(zoom_level, current_zoom_level)) |
105 continue; | 106 continue; |
106 if (zoom_level > current_zoom_level) { | 107 if (zoom_level > current_zoom_level) { |
107 web_contents->SetZoomLevel(zoom_level); | 108 content::HostZoomMap::SetZoomLevel(web_contents, zoom_level); |
108 content::RecordAction(UserMetricsAction("ZoomPlus")); | 109 content::RecordAction(UserMetricsAction("ZoomPlus")); |
109 return; | 110 return; |
110 } | 111 } |
111 } | 112 } |
112 content::RecordAction(UserMetricsAction("ZoomPlus_AtMaximum")); | 113 content::RecordAction(UserMetricsAction("ZoomPlus_AtMaximum")); |
113 } | 114 } |
114 } | 115 } |
115 | 116 |
116 } // namespace chrome_page_zoom | 117 } // namespace chrome_page_zoom |
OLD | NEW |