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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/ui/browser.h" 5 #include "chrome/browser/ui/browser.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #endif // OS_WIN 10 #endif // OS_WIN
11 11
12 #include <algorithm> 12 #include <algorithm>
13 #include <cmath>
13 #include <string> 14 #include <string>
14 15
15 #include "base/base_paths.h" 16 #include "base/base_paths.h"
16 #include "base/command_line.h" 17 #include "base/command_line.h"
17 #include "base/logging.h" 18 #include "base/logging.h"
18 #include "base/metrics/field_trial.h" 19 #include "base/metrics/field_trial.h"
19 #include "base/metrics/histogram.h" 20 #include "base/metrics/histogram.h"
20 #include "base/path_service.h" 21 #include "base/path_service.h"
21 #include "base/string_number_conversions.h" 22 #include "base/string_number_conversions.h"
22 #include "base/string_util.h" 23 #include "base/string_util.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 #include "content/browser/site_instance.h" 147 #include "content/browser/site_instance.h"
147 #include "content/browser/tab_contents/interstitial_page.h" 148 #include "content/browser/tab_contents/interstitial_page.h"
148 #include "content/browser/tab_contents/navigation_controller.h" 149 #include "content/browser/tab_contents/navigation_controller.h"
149 #include "content/browser/tab_contents/navigation_entry.h" 150 #include "content/browser/tab_contents/navigation_entry.h"
150 #include "content/browser/tab_contents/tab_contents_view.h" 151 #include "content/browser/tab_contents/tab_contents_view.h"
151 #include "content/browser/user_metrics.h" 152 #include "content/browser/user_metrics.h"
152 #include "content/public/browser/notification_service.h" 153 #include "content/public/browser/notification_service.h"
153 #include "content/public/browser/notification_details.h" 154 #include "content/public/browser/notification_details.h"
154 #include "content/public/common/content_restriction.h" 155 #include "content/public/common/content_restriction.h"
155 #include "content/public/common/content_switches.h" 156 #include "content/public/common/content_switches.h"
157 #include "content/public/common/page_zoom.h"
156 #include "grit/chromium_strings.h" 158 #include "grit/chromium_strings.h"
157 #include "grit/generated_resources.h" 159 #include "grit/generated_resources.h"
158 #include "grit/locale_settings.h" 160 #include "grit/locale_settings.h"
159 #include "grit/theme_resources_standard.h" 161 #include "grit/theme_resources_standard.h"
160 #include "net/base/cookie_monster.h" 162 #include "net/base/cookie_monster.h"
161 #include "net/base/net_util.h" 163 #include "net/base/net_util.h"
162 #include "net/base/registry_controlled_domain.h" 164 #include "net/base/registry_controlled_domain.h"
163 #include "net/url_request/url_request_context.h" 165 #include "net/url_request/url_request_context.h"
166 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
164 #include "ui/base/animation/animation.h" 167 #include "ui/base/animation/animation.h"
165 #include "ui/base/l10n/l10n_util.h" 168 #include "ui/base/l10n/l10n_util.h"
166 #include "ui/gfx/point.h" 169 #include "ui/gfx/point.h"
167 #include "webkit/glue/web_intent_data.h" 170 #include "webkit/glue/web_intent_data.h"
168 #include "webkit/glue/webkit_glue.h" 171 #include "webkit/glue/webkit_glue.h"
169 #include "webkit/glue/window_open_disposition.h" 172 #include "webkit/glue/window_open_disposition.h"
170 173
171 #if defined(OS_WIN) 174 #if defined(OS_WIN)
172 #include "chrome/browser/autofill/autofill_ie_toolbar_import_win.h" 175 #include "chrome/browser/autofill/autofill_ie_toolbar_import_win.h"
173 #include "chrome/browser/shell_integration.h" 176 #include "chrome/browser/shell_integration.h"
(...skipping 1786 matching lines...) Expand 10 before | Expand all | Expand 10 after
1960 1963
1961 void Browser::FindPrevious() { 1964 void Browser::FindPrevious() {
1962 UserMetrics::RecordAction(UserMetricsAction("FindPrevious")); 1965 UserMetrics::RecordAction(UserMetricsAction("FindPrevious"));
1963 FindInPage(true, false); 1966 FindInPage(true, false);
1964 } 1967 }
1965 1968
1966 void Browser::Zoom(content::PageZoom zoom) { 1969 void Browser::Zoom(content::PageZoom zoom) {
1967 if (is_devtools()) 1970 if (is_devtools())
1968 return; 1971 return;
1969 1972
1970 static const UserMetricsAction kActions[] = { 1973 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.
1971 UserMetricsAction("ZoomMinus"), 1974 if (!host)
1972 UserMetricsAction("ZoomNormal"), 1975 return;
1973 UserMetricsAction("ZoomPlus")
1974 };
1975 1976
1976 UserMetrics::RecordAction(kActions[zoom - content::PAGE_ZOOM_OUT]); 1977 if (zoom == content::PAGE_ZOOM_RESET) {
1977 TabContentsWrapper* tab_contents = GetSelectedTabContentsWrapper(); 1978 host->SetZoomLevel(0);
1978 RenderViewHost* host = tab_contents->render_view_host(); 1979 UserMetrics::RecordAction(UserMetricsAction("ZoomNormal"));
1979 host->Zoom(zoom); 1980 return;
1981 }
1982
1983 double current_zoom_level = GetSelectedTabContents()->GetZoomLevel();
1984 double default_zoom_level =
1985 profile_->GetPrefs()->GetDouble(prefs::kDefaultZoomLevel);
1986
1987 // Generate a vector of zoom level values from an array of known preset
1988 // values. The values in content::kPresetZoomFactors will already be in
1989 // sorted order.
1990 std::vector<double> zoom_levels;
1991 bool found_default = false;
1992 for (int i = 0; i < content::kPresetZoomFactorsCount; i++) {
1993 double zoom_level =
1994 WebKit::WebView::zoomFactorToZoomLevel(content::kPresetZoomFactors[i]);
1995 if (std::fabs(zoom_level - default_zoom_level) <=
1996 content::kPageZoomEpsilon)
1997 found_default = true;
1998 zoom_levels.push_back(zoom_level);
1999 }
2000 // If the preset array did not contain the user's default zoom value,
2001 // append it to the vector and then sort.
2002 if (!found_default) {
2003 zoom_levels.push_back(default_zoom_level);
2004 std::sort(zoom_levels.begin(), zoom_levels.end());
2005 }
2006
2007 if (zoom == content::PAGE_ZOOM_OUT) {
2008 // Iterate through the zoom levels in reverse order to find the next
2009 // lower level based on the current zoom level for this page.
2010 for (std::vector<double>::reverse_iterator i = zoom_levels.rbegin();
2011 i != zoom_levels.rend(); ++i) {
2012 double zoom_level = *i;
2013 if (std::fabs(zoom_level - current_zoom_level) <=
2014 content::kPageZoomEpsilon)
2015 continue;
2016 if (zoom_level < current_zoom_level) {
2017 host->SetZoomLevel(zoom_level);
2018 break;
2019 }
2020 }
2021 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.
2022 } else {
2023 // Iterate through the zoom levels in normal order to find the next
2024 // higher level based on the current zoom level for this page.
2025 for (std::vector<double>::const_iterator i = zoom_levels.begin();
2026 i != zoom_levels.end(); ++i) {
2027 double zoom_level = *i;
2028 if (std::fabs(zoom_level - current_zoom_level) <=
2029 content::kPageZoomEpsilon)
2030 continue;
2031 if (zoom_level > current_zoom_level) {
2032 host->SetZoomLevel(zoom_level);
2033 break;
2034 }
2035 }
2036 UserMetrics::RecordAction(UserMetricsAction("ZoomPlus"));
2037 }
1980 } 2038 }
1981 2039
1982 void Browser::FocusToolbar() { 2040 void Browser::FocusToolbar() {
1983 UserMetrics::RecordAction(UserMetricsAction("FocusToolbar")); 2041 UserMetrics::RecordAction(UserMetricsAction("FocusToolbar"));
1984 window_->FocusToolbar(); 2042 window_->FocusToolbar();
1985 } 2043 }
1986 2044
1987 void Browser::FocusAppMenu() { 2045 void Browser::FocusAppMenu() {
1988 UserMetrics::RecordAction(UserMetricsAction("FocusAppMenu")); 2046 UserMetrics::RecordAction(UserMetricsAction("FocusAppMenu"));
1989 window_->FocusAppMenu(); 2047 window_->FocusAppMenu();
(...skipping 3516 matching lines...) Expand 10 before | Expand all | Expand 10 after
5506 } 5564 }
5507 5565
5508 void Browser::UpdateFullscreenExitBubbleContent() { 5566 void Browser::UpdateFullscreenExitBubbleContent() {
5509 GURL url; 5567 GURL url;
5510 if (fullscreened_tab_) 5568 if (fullscreened_tab_)
5511 url = fullscreened_tab_->tab_contents()->GetURL(); 5569 url = fullscreened_tab_->tab_contents()->GetURL();
5512 5570
5513 window_->UpdateFullscreenExitBubbleContent( 5571 window_->UpdateFullscreenExitBubbleContent(
5514 url, GetFullscreenExitBubbleType()); 5572 url, GetFullscreenExitBubbleType());
5515 } 5573 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698