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

Side by Side Diff: chrome/browser/chrome_page_zoom.cc

Issue 10736037: Enable keyboard shortcuts and some menu commands for browserless Panels. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Synced Created 8 years, 5 months 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
« no previous file with comments | « chrome/browser/chrome_page_zoom.h ('k') | chrome/browser/ui/browser_commands.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 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 "content/public/common/page_zoom.h" 11 #include "content/public/browser/render_view_host.h"
12 #include "content/public/browser/user_metrics.h"
13 #include "content/public/browser/web_contents.h"
14 #include "content/public/common/renderer_preferences.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
13 16
17 using content::UserMetricsAction;
18
14 namespace chrome_page_zoom { 19 namespace chrome_page_zoom {
15 20
16 enum PageZoomValueType { 21 enum PageZoomValueType {
17 PAGE_ZOOM_VALUE_TYPE_FACTOR, 22 PAGE_ZOOM_VALUE_TYPE_FACTOR,
18 PAGE_ZOOM_VALUE_TYPE_LEVEL, 23 PAGE_ZOOM_VALUE_TYPE_LEVEL,
19 }; 24 };
20 25
21 std::vector<double> PresetZoomValues(PageZoomValueType value_type, 26 std::vector<double> PresetZoomValues(PageZoomValueType value_type,
22 double custom_value) { 27 double custom_value) {
23 // Generate a vector of zoom values from an array of known preset 28 // Generate a vector of zoom values from an array of known preset
(...skipping 25 matching lines...) Expand all
49 } 54 }
50 55
51 std::vector<double> PresetZoomFactors(double custom_factor) { 56 std::vector<double> PresetZoomFactors(double custom_factor) {
52 return PresetZoomValues(PAGE_ZOOM_VALUE_TYPE_FACTOR, custom_factor); 57 return PresetZoomValues(PAGE_ZOOM_VALUE_TYPE_FACTOR, custom_factor);
53 } 58 }
54 59
55 std::vector<double> PresetZoomLevels(double custom_level) { 60 std::vector<double> PresetZoomLevels(double custom_level) {
56 return PresetZoomValues(PAGE_ZOOM_VALUE_TYPE_LEVEL, custom_level); 61 return PresetZoomValues(PAGE_ZOOM_VALUE_TYPE_LEVEL, custom_level);
57 } 62 }
58 63
64 void Zoom(content::WebContents* web_contents, content::PageZoom zoom) {
65 content::RenderViewHost* host = web_contents->GetRenderViewHost();
66 if (zoom == content::PAGE_ZOOM_RESET) {
67 host->SetZoomLevel(0);
68 content::RecordAction(UserMetricsAction("ZoomNormal"));
69 return;
70 }
71
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
77 // the default level added if necessary.
78 std::vector<double> zoom_levels = PresetZoomLevels(default_zoom_level);
79
80 if (zoom == content::PAGE_ZOOM_OUT) {
81 // Iterate through the zoom levels in reverse order to find the next
82 // lower level based on the current zoom level for this page.
83 for (std::vector<double>::reverse_iterator i = zoom_levels.rbegin();
84 i != zoom_levels.rend(); ++i) {
85 double zoom_level = *i;
86 if (content::ZoomValuesEqual(zoom_level, current_zoom_level))
87 continue;
88 if (zoom_level < current_zoom_level) {
89 host->SetZoomLevel(zoom_level);
90 content::RecordAction(UserMetricsAction("ZoomMinus"));
91 return;
92 }
93 content::RecordAction(UserMetricsAction("ZoomMinus_AtMinimum"));
94 }
95 } else {
96 // Iterate through the zoom levels in normal order to find the next
97 // higher level based on the current zoom level for this page.
98 for (std::vector<double>::const_iterator i = zoom_levels.begin();
99 i != zoom_levels.end(); ++i) {
100 double zoom_level = *i;
101 if (content::ZoomValuesEqual(zoom_level, current_zoom_level))
102 continue;
103 if (zoom_level > current_zoom_level) {
104 host->SetZoomLevel(zoom_level);
105 content::RecordAction(UserMetricsAction("ZoomPlus"));
106 return;
107 }
108 }
109 content::RecordAction(UserMetricsAction("ZoomPlus_AtMaximum"));
110 }
111 }
112
59 } // namespace chrome_page_zoom 113 } // namespace chrome_page_zoom
OLDNEW
« no previous file with comments | « chrome/browser/chrome_page_zoom.h ('k') | chrome/browser/ui/browser_commands.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698