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 "chrome/browser/chrome_page_zoom_constants.h" | 10 #include "chrome/browser/chrome_page_zoom_constants.h" |
| 11 #include "chrome/browser/prefs/pref_service.h" |
| 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/common/pref_names.h" |
11 #include "content/public/browser/render_view_host.h" | 14 #include "content/public/browser/render_view_host.h" |
12 #include "content/public/browser/user_metrics.h" | 15 #include "content/public/browser/user_metrics.h" |
13 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
14 #include "content/public/common/renderer_preferences.h" | 17 #include "content/public/common/renderer_preferences.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
16 | 19 |
17 using content::UserMetricsAction; | 20 using content::UserMetricsAction; |
18 | 21 |
19 namespace chrome_page_zoom { | 22 namespace chrome_page_zoom { |
20 | 23 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 std::vector<double> PresetZoomFactors(double custom_factor) { | 59 std::vector<double> PresetZoomFactors(double custom_factor) { |
57 return PresetZoomValues(PAGE_ZOOM_VALUE_TYPE_FACTOR, custom_factor); | 60 return PresetZoomValues(PAGE_ZOOM_VALUE_TYPE_FACTOR, custom_factor); |
58 } | 61 } |
59 | 62 |
60 std::vector<double> PresetZoomLevels(double custom_level) { | 63 std::vector<double> PresetZoomLevels(double custom_level) { |
61 return PresetZoomValues(PAGE_ZOOM_VALUE_TYPE_LEVEL, custom_level); | 64 return PresetZoomValues(PAGE_ZOOM_VALUE_TYPE_LEVEL, custom_level); |
62 } | 65 } |
63 | 66 |
64 void Zoom(content::WebContents* web_contents, content::PageZoom zoom) { | 67 void Zoom(content::WebContents* web_contents, content::PageZoom zoom) { |
65 content::RenderViewHost* host = web_contents->GetRenderViewHost(); | 68 content::RenderViewHost* host = web_contents->GetRenderViewHost(); |
| 69 double current_zoom_level = web_contents->GetZoomLevel(); |
| 70 double default_zoom_level = |
| 71 Profile::FromBrowserContext(web_contents->GetBrowserContext())-> |
| 72 GetPrefs()->GetDouble(prefs::kDefaultZoomLevel); |
| 73 |
66 if (zoom == content::PAGE_ZOOM_RESET) { | 74 if (zoom == content::PAGE_ZOOM_RESET) { |
67 host->SetZoomLevel(0); | 75 host->SetZoomLevel(default_zoom_level); |
68 content::RecordAction(UserMetricsAction("ZoomNormal")); | 76 content::RecordAction(UserMetricsAction("ZoomNormal")); |
69 return; | 77 return; |
70 } | 78 } |
71 | 79 |
72 double current_zoom_level = web_contents->GetZoomLevel(); | |
73 double default_zoom_level = | |
74 web_contents->GetMutableRendererPrefs()->default_zoom_level; | |
75 | |
76 // 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 |
77 // the default level added if necessary. | 81 // the default level added if necessary. |
78 std::vector<double> zoom_levels = PresetZoomLevels(default_zoom_level); | 82 std::vector<double> zoom_levels = PresetZoomLevels(default_zoom_level); |
79 | 83 |
80 if (zoom == content::PAGE_ZOOM_OUT) { | 84 if (zoom == content::PAGE_ZOOM_OUT) { |
81 // 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 |
82 // lower level based on the current zoom level for this page. | 86 // lower level based on the current zoom level for this page. |
83 for (std::vector<double>::reverse_iterator i = zoom_levels.rbegin(); | 87 for (std::vector<double>::reverse_iterator i = zoom_levels.rbegin(); |
84 i != zoom_levels.rend(); ++i) { | 88 i != zoom_levels.rend(); ++i) { |
85 double zoom_level = *i; | 89 double zoom_level = *i; |
(...skipping 18 matching lines...) Expand all Loading... |
104 host->SetZoomLevel(zoom_level); | 108 host->SetZoomLevel(zoom_level); |
105 content::RecordAction(UserMetricsAction("ZoomPlus")); | 109 content::RecordAction(UserMetricsAction("ZoomPlus")); |
106 return; | 110 return; |
107 } | 111 } |
108 } | 112 } |
109 content::RecordAction(UserMetricsAction("ZoomPlus_AtMaximum")); | 113 content::RecordAction(UserMetricsAction("ZoomPlus_AtMaximum")); |
110 } | 114 } |
111 } | 115 } |
112 | 116 |
113 } // namespace chrome_page_zoom | 117 } // namespace chrome_page_zoom |
OLD | NEW |