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

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

Issue 8528011: Page zoom improvements (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: One last(?) tweak. Created 9 years 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <cmath>
6
7 #include "chrome/browser/chrome_page_zoom.h"
8 #include "content/public/common/page_zoom.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
10
11 namespace chrome_page_zoom {
12
13 enum PageZoomValueType {
14 PAGE_ZOOM_VALUE_TYPE_FACTOR,
15 PAGE_ZOOM_VALUE_TYPE_LEVEL,
16 };
17
18 const double kPresetZoomFactors[] = { 0.25, 0.333, 0.5, 0.666, 0.75, 0.9, 1.0,
19 1.1, 1.25, 1.5, 1.75, 2.0, 2.5, 3.0, 4.0,
20 5.0 };
21
22 std::vector<double> PresetZoomValues(PageZoomValueType value_type,
23 double custom_value) {
24 // Generate a vector of zoom values from an array of known preset
25 // factors. The values in content::kPresetZoomFactors will already be in
26 // sorted order.
27 std::vector<double> zoom_values;
28 bool found_custom = false;
29 for (size_t i = 0; i < arraysize(kPresetZoomFactors); i++) {
30 double zoom_value = kPresetZoomFactors[i];
31 if (value_type == PAGE_ZOOM_VALUE_TYPE_LEVEL)
32 zoom_value = WebKit::WebView::zoomFactorToZoomLevel(zoom_value);
33 if (content::ZoomValuesEqual(zoom_value, custom_value))
34 found_custom = true;
35 zoom_values.push_back(zoom_value);
36 }
37 // If the preset array did not contain the custom value, append it to the
38 // vector and then sort.
39 double min = value_type == PAGE_ZOOM_VALUE_TYPE_LEVEL ?
40 WebKit::WebView::zoomFactorToZoomLevel(content::kMinimumZoomFactor) :
41 content::kMinimumZoomFactor;
42 double max = value_type == PAGE_ZOOM_VALUE_TYPE_LEVEL ?
43 WebKit::WebView::zoomFactorToZoomLevel(content::kMaximumZoomFactor) :
44 content::kMaximumZoomFactor;
45 if (!found_custom && custom_value > min && custom_value < max) {
46 zoom_values.push_back(custom_value);
47 std::sort(zoom_values.begin(), zoom_values.end());
48 }
49 return zoom_values;
50 }
51
52 std::vector<double> PresetZoomFactors(double custom_factor) {
53 return PresetZoomValues(PAGE_ZOOM_VALUE_TYPE_FACTOR, custom_factor);
54 }
55
56 std::vector<double> PresetZoomLevels(double custom_level) {
57 return PresetZoomValues(PAGE_ZOOM_VALUE_TYPE_LEVEL, custom_level);
58 }
59
60 } // namespace chrome_page_zoom
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698