Chromium Code Reviews| 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 // TODO(wjmaclean) Should we be talking to HostZoomMap directly instead? |
|
Fady Samuel
2014/06/12 19:46:57
Remove comment?
| |
| 80 zoom_controller->SetZoomLevel(default_zoom_level); | |
| 76 content::RecordAction(UserMetricsAction("ZoomNormal")); | 81 content::RecordAction(UserMetricsAction("ZoomNormal")); |
| 77 return; | 82 return; |
| 78 } | 83 } |
| 79 | 84 |
| 80 // Generate a vector of zoom levels from an array of known presets along with | 85 // Generate a vector of zoom levels from an array of known presets along with |
| 81 // the default level added if necessary. | 86 // the default level added if necessary. |
| 82 std::vector<double> zoom_levels = PresetZoomLevels(default_zoom_level); | 87 std::vector<double> zoom_levels = PresetZoomLevels(default_zoom_level); |
| 83 | 88 |
| 84 if (zoom == content::PAGE_ZOOM_OUT) { | 89 if (zoom == content::PAGE_ZOOM_OUT) { |
| 85 // Iterate through the zoom levels in reverse order to find the next | 90 // Iterate through the zoom levels in reverse order to find the next |
| 86 // lower level based on the current zoom level for this page. | 91 // lower level based on the current zoom level for this page. |
| 87 for (std::vector<double>::reverse_iterator i = zoom_levels.rbegin(); | 92 for (std::vector<double>::reverse_iterator i = zoom_levels.rbegin(); |
| 88 i != zoom_levels.rend(); ++i) { | 93 i != zoom_levels.rend(); ++i) { |
| 89 double zoom_level = *i; | 94 double zoom_level = *i; |
| 90 if (content::ZoomValuesEqual(zoom_level, current_zoom_level)) | 95 if (content::ZoomValuesEqual(zoom_level, current_zoom_level)) |
| 91 continue; | 96 continue; |
| 92 if (zoom_level < current_zoom_level) { | 97 if (zoom_level < current_zoom_level) { |
| 93 content::HostZoomMap::SetZoomLevel(web_contents, zoom_level); | 98 // TODO(wjmaclean) Should we be talking to HostZoomMap directly instead? |
|
Fady Samuel
2014/06/12 19:46:57
Remove comment.
| |
| 99 zoom_controller->SetZoomLevel(zoom_level); | |
| 94 content::RecordAction(UserMetricsAction("ZoomMinus")); | 100 content::RecordAction(UserMetricsAction("ZoomMinus")); |
| 95 return; | 101 return; |
| 96 } | 102 } |
| 97 content::RecordAction(UserMetricsAction("ZoomMinus_AtMinimum")); | 103 content::RecordAction(UserMetricsAction("ZoomMinus_AtMinimum")); |
| 98 } | 104 } |
| 99 } else { | 105 } else { |
| 100 // Iterate through the zoom levels in normal order to find the next | 106 // Iterate through the zoom levels in normal order to find the next |
| 101 // higher level based on the current zoom level for this page. | 107 // higher level based on the current zoom level for this page. |
| 102 for (std::vector<double>::const_iterator i = zoom_levels.begin(); | 108 for (std::vector<double>::const_iterator i = zoom_levels.begin(); |
| 103 i != zoom_levels.end(); ++i) { | 109 i != zoom_levels.end(); ++i) { |
| 104 double zoom_level = *i; | 110 double zoom_level = *i; |
| 105 if (content::ZoomValuesEqual(zoom_level, current_zoom_level)) | 111 if (content::ZoomValuesEqual(zoom_level, current_zoom_level)) |
| 106 continue; | 112 continue; |
| 107 if (zoom_level > current_zoom_level) { | 113 if (zoom_level > current_zoom_level) { |
| 108 content::HostZoomMap::SetZoomLevel(web_contents, zoom_level); | 114 // TODO(wjmaclean) Should we be talking to HostZoomMap directly instead? |
|
Fady Samuel
2014/06/12 19:46:57
Remove comment.
| |
| 115 zoom_controller->SetZoomLevel(zoom_level); | |
| 109 content::RecordAction(UserMetricsAction("ZoomPlus")); | 116 content::RecordAction(UserMetricsAction("ZoomPlus")); |
| 110 return; | 117 return; |
| 111 } | 118 } |
| 112 } | 119 } |
| 113 content::RecordAction(UserMetricsAction("ZoomPlus_AtMaximum")); | 120 content::RecordAction(UserMetricsAction("ZoomPlus_AtMaximum")); |
| 114 } | 121 } |
| 115 } | 122 } |
| 116 | 123 |
| 117 } // namespace chrome_page_zoom | 124 } // namespace chrome_page_zoom |
| OLD | NEW |