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