Index: chrome/browser/ui/browser.cc |
=================================================================== |
--- chrome/browser/ui/browser.cc (revision 109526) |
+++ chrome/browser/ui/browser.cc (working copy) |
@@ -153,6 +153,7 @@ |
#include "content/public/browser/notification_details.h" |
#include "content/public/common/content_restriction.h" |
#include "content/public/common/content_switches.h" |
+#include "content/public/common/page_zoom.h" |
#include "grit/chromium_strings.h" |
#include "grit/generated_resources.h" |
#include "grit/locale_settings.h" |
@@ -1967,16 +1968,55 @@ |
if (is_devtools()) |
return; |
- static const UserMetricsAction kActions[] = { |
- UserMetricsAction("ZoomMinus"), |
- UserMetricsAction("ZoomNormal"), |
- UserMetricsAction("ZoomPlus") |
- }; |
+ RenderViewHost* host = GetSelectedTabContentsWrapper()->render_view_host(); |
+ if (zoom == content::PAGE_ZOOM_RESET) { |
+ host->SetZoomLevel(0); |
+ UserMetrics::RecordAction(UserMetricsAction("ZoomNormal")); |
+ return; |
+ } |
- UserMetrics::RecordAction(kActions[zoom - content::PAGE_ZOOM_OUT]); |
- TabContentsWrapper* tab_contents = GetSelectedTabContentsWrapper(); |
- RenderViewHost* host = tab_contents->render_view_host(); |
- host->Zoom(zoom); |
+ double current_zoom_level = GetSelectedTabContents()->GetZoomLevel(); |
+ double default_zoom_level = |
+ profile_->GetPrefs()->GetDouble(prefs::kDefaultZoomLevel); |
+ |
+ // Generate a vector of zoom levels from an array of known presets along with |
+ // the default level added if necessary. |
+ std::vector<double> zoom_levels = |
+ content::PageZoomHelpers::PresetLevelsWithCustomValue(default_zoom_level); |
+ |
+ if (zoom == content::PAGE_ZOOM_OUT) { |
+ // Iterate through the zoom levels in reverse order to find the next |
+ // lower level based on the current zoom level for this page. |
+ for (std::vector<double>::reverse_iterator i = zoom_levels.rbegin(); |
+ i != zoom_levels.rend(); ++i) { |
+ double zoom_level = *i; |
+ if (content::PageZoomHelpers::ZoomValuesEqual(zoom_level, |
+ current_zoom_level)) |
+ continue; |
+ if (zoom_level < current_zoom_level) { |
+ host->SetZoomLevel(zoom_level); |
+ UserMetrics::RecordAction(UserMetricsAction("ZoomMinus")); |
+ return; |
+ } |
+ UserMetrics::RecordAction(UserMetricsAction("ZoomMinus_AtMinimum")); |
+ } |
+ } else { |
+ // Iterate through the zoom levels in normal order to find the next |
+ // higher level based on the current zoom level for this page. |
+ for (std::vector<double>::const_iterator i = zoom_levels.begin(); |
+ i != zoom_levels.end(); ++i) { |
+ double zoom_level = *i; |
+ if (content::PageZoomHelpers::ZoomValuesEqual(zoom_level, |
+ current_zoom_level)) |
+ continue; |
+ if (zoom_level > current_zoom_level) { |
+ host->SetZoomLevel(zoom_level); |
+ UserMetrics::RecordAction(UserMetricsAction("ZoomPlus")); |
+ return; |
+ } |
+ } |
+ UserMetrics::RecordAction(UserMetricsAction("ZoomPlus_AtMaximum")); |
+ } |
} |
void Browser::FocusToolbar() { |