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/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 { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 = web_contents->GetZoomLevel(); |
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 |
| 74 ZoomController* zoom_controller = |
| 75 ZoomController::FromWebContents(web_contents); |
| 76 |
73 if (zoom == content::PAGE_ZOOM_RESET) { | 77 if (zoom == content::PAGE_ZOOM_RESET) { |
74 web_contents->SetZoomLevel(default_zoom_level); | 78 zoom_controller->SetZoomLevel(default_zoom_level); |
75 content::RecordAction(UserMetricsAction("ZoomNormal")); | 79 content::RecordAction(UserMetricsAction("ZoomNormal")); |
76 return; | 80 return; |
77 } | 81 } |
78 | 82 |
79 // Generate a vector of zoom levels from an array of known presets along with | 83 // Generate a vector of zoom levels from an array of known presets along with |
80 // the default level added if necessary. | 84 // the default level added if necessary. |
81 std::vector<double> zoom_levels = PresetZoomLevels(default_zoom_level); | 85 std::vector<double> zoom_levels = PresetZoomLevels(default_zoom_level); |
82 | 86 |
83 if (zoom == content::PAGE_ZOOM_OUT) { | 87 if (zoom == content::PAGE_ZOOM_OUT) { |
84 // Iterate through the zoom levels in reverse order to find the next | 88 // Iterate through the zoom levels in reverse order to find the next |
85 // lower level based on the current zoom level for this page. | 89 // lower level based on the current zoom level for this page. |
86 for (std::vector<double>::reverse_iterator i = zoom_levels.rbegin(); | 90 for (std::vector<double>::reverse_iterator i = zoom_levels.rbegin(); |
87 i != zoom_levels.rend(); ++i) { | 91 i != zoom_levels.rend(); ++i) { |
88 double zoom_level = *i; | 92 double zoom_level = *i; |
89 if (content::ZoomValuesEqual(zoom_level, current_zoom_level)) | 93 if (content::ZoomValuesEqual(zoom_level, current_zoom_level)) |
90 continue; | 94 continue; |
91 if (zoom_level < current_zoom_level) { | 95 if (zoom_level < current_zoom_level) { |
92 web_contents->SetZoomLevel(zoom_level); | 96 zoom_controller->SetZoomLevel(zoom_level); |
93 content::RecordAction(UserMetricsAction("ZoomMinus")); | 97 content::RecordAction(UserMetricsAction("ZoomMinus")); |
94 return; | 98 return; |
95 } | 99 } |
96 content::RecordAction(UserMetricsAction("ZoomMinus_AtMinimum")); | 100 content::RecordAction(UserMetricsAction("ZoomMinus_AtMinimum")); |
97 } | 101 } |
98 } else { | 102 } else { |
99 // Iterate through the zoom levels in normal order to find the next | 103 // Iterate through the zoom levels in normal order to find the next |
100 // higher level based on the current zoom level for this page. | 104 // higher level based on the current zoom level for this page. |
101 for (std::vector<double>::const_iterator i = zoom_levels.begin(); | 105 for (std::vector<double>::const_iterator i = zoom_levels.begin(); |
102 i != zoom_levels.end(); ++i) { | 106 i != zoom_levels.end(); ++i) { |
103 double zoom_level = *i; | 107 double zoom_level = *i; |
104 if (content::ZoomValuesEqual(zoom_level, current_zoom_level)) | 108 if (content::ZoomValuesEqual(zoom_level, current_zoom_level)) |
105 continue; | 109 continue; |
106 if (zoom_level > current_zoom_level) { | 110 if (zoom_level > current_zoom_level) { |
107 web_contents->SetZoomLevel(zoom_level); | 111 zoom_controller->SetZoomLevel(zoom_level); |
108 content::RecordAction(UserMetricsAction("ZoomPlus")); | 112 content::RecordAction(UserMetricsAction("ZoomPlus")); |
109 return; | 113 return; |
110 } | 114 } |
111 } | 115 } |
112 content::RecordAction(UserMetricsAction("ZoomPlus_AtMaximum")); | 116 content::RecordAction(UserMetricsAction("ZoomPlus_AtMaximum")); |
113 } | 117 } |
114 } | 118 } |
115 | 119 |
116 } // namespace chrome_page_zoom | 120 } // namespace chrome_page_zoom |
OLD | NEW |