Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(291)

Unified Diff: chrome/browser/ui/browser.cc

Issue 8528011: Page zoom improvements (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/browser.cc
===================================================================
--- chrome/browser/ui/browser.cc (revision 109526)
+++ chrome/browser/ui/browser.cc (working copy)
@@ -10,6 +10,7 @@
#endif // OS_WIN
#include <algorithm>
+#include <cmath>
#include <string>
#include "base/base_paths.h"
@@ -153,6 +154,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"
@@ -161,6 +163,7 @@
#include "net/base/net_util.h"
#include "net/base/registry_controlled_domain.h"
#include "net/url_request/url_request_context.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
#include "ui/base/animation/animation.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/point.h"
@@ -1967,16 +1970,71 @@
if (is_devtools())
return;
- static const UserMetricsAction kActions[] = {
- UserMetricsAction("ZoomMinus"),
- UserMetricsAction("ZoomNormal"),
- UserMetricsAction("ZoomPlus")
- };
+ RenderViewHost* host = GetSelectedTabContentsWrapper()->render_view_host();
James Hawkins 2011/11/14 18:09:05 When is |host| NULL?
csilv 2011/11/15 02:26:49 Shouldn't happen, removed.
+ if (!host)
+ return;
- UserMetrics::RecordAction(kActions[zoom - content::PAGE_ZOOM_OUT]);
- TabContentsWrapper* tab_contents = GetSelectedTabContentsWrapper();
- RenderViewHost* host = tab_contents->render_view_host();
- host->Zoom(zoom);
+ if (zoom == content::PAGE_ZOOM_RESET) {
+ host->SetZoomLevel(0);
+ UserMetrics::RecordAction(UserMetricsAction("ZoomNormal"));
+ return;
+ }
+
+ double current_zoom_level = GetSelectedTabContents()->GetZoomLevel();
+ double default_zoom_level =
+ profile_->GetPrefs()->GetDouble(prefs::kDefaultZoomLevel);
+
+ // Generate a vector of zoom level values from an array of known preset
+ // values. The values in content::kPresetZoomFactors will already be in
+ // sorted order.
+ std::vector<double> zoom_levels;
+ bool found_default = false;
+ for (int i = 0; i < content::kPresetZoomFactorsCount; i++) {
+ double zoom_level =
+ WebKit::WebView::zoomFactorToZoomLevel(content::kPresetZoomFactors[i]);
+ if (std::fabs(zoom_level - default_zoom_level) <=
+ content::kPageZoomEpsilon)
+ found_default = true;
+ zoom_levels.push_back(zoom_level);
+ }
+ // If the preset array did not contain the user's default zoom value,
+ // append it to the vector and then sort.
+ if (!found_default) {
+ zoom_levels.push_back(default_zoom_level);
+ std::sort(zoom_levels.begin(), zoom_levels.end());
+ }
+
+ 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 (std::fabs(zoom_level - current_zoom_level) <=
+ content::kPageZoomEpsilon)
+ continue;
+ if (zoom_level < current_zoom_level) {
+ host->SetZoomLevel(zoom_level);
+ break;
+ }
+ }
+ UserMetrics::RecordAction(UserMetricsAction("ZoomMinus"));
James Hawkins 2011/11/14 18:09:05 For the sake of posterity, it would be interesting
csilv 2011/11/15 02:26:49 Done.
+ } 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 (std::fabs(zoom_level - current_zoom_level) <=
+ content::kPageZoomEpsilon)
+ continue;
+ if (zoom_level > current_zoom_level) {
+ host->SetZoomLevel(zoom_level);
+ break;
+ }
+ }
+ UserMetrics::RecordAction(UserMetricsAction("ZoomPlus"));
+ }
}
void Browser::FocusToolbar() {

Powered by Google App Engine
This is Rietveld 408576698