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

Side by Side Diff: content/public/common/page_zoom.cc

Issue 8528011: Page zoom improvements (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Tweak, Tweak 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
« no previous file with comments | « content/public/common/page_zoom.h ('k') | content/public/common/page_zoom_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "content/public/common/page_zoom.h"
8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
9
10 namespace content {
11
12 enum PageZoomValueType {
13 PAGE_ZOOM_VALUE_TYPE_FACTOR,
14 PAGE_ZOOM_VALUE_TYPE_LEVEL,
15 };
16
17 const double kMinimumZoomFactor = 0.25;
18 const double kMaximumZoomFactor = 5.0;
19
20 const double kPresetZoomFactors[] = { 0.25, 0.333, 0.5, 0.666, 0.75, 0.9, 1.0,
jam 2011/11/21 18:24:39 these preset values are all chrome-specific. other
csilv 2011/11/21 21:44:58 Done (relocated to chrome/browser as recommended).
21 1.1, 1.25, 1.5, 1.75, 2.0, 2.5, 3.0, 4.0,
22 5.0 };
23
24 std::vector<double> PresetZoomValues(PageZoomValueType value_type,
25 double custom_value) {
26 // Generate a vector of zoom values from an array of known preset
27 // factors. The values in content::kPresetZoomFactors will already be in
28 // sorted order.
29 std::vector<double> zoom_values;
30 bool found_custom = false;
31 for (size_t i = 0; i < arraysize(kPresetZoomFactors); i++) {
32 double zoom_value = content::kPresetZoomFactors[i];
33 if (value_type == PAGE_ZOOM_VALUE_TYPE_LEVEL)
34 zoom_value = WebKit::WebView::zoomFactorToZoomLevel(zoom_value);
35 if (ZoomValuesEqual(zoom_value, custom_value))
36 found_custom = true;
37 zoom_values.push_back(zoom_value);
38 }
39 // If the preset array did not contain the custom value, append it to the
40 // vector and then sort.
41 double min = value_type == PAGE_ZOOM_VALUE_TYPE_LEVEL ?
42 WebKit::WebView::zoomFactorToZoomLevel(kMinimumZoomFactor) :
43 kMinimumZoomFactor;
44 double max = value_type == PAGE_ZOOM_VALUE_TYPE_LEVEL ?
45 WebKit::WebView::zoomFactorToZoomLevel(kMaximumZoomFactor) :
46 kMaximumZoomFactor;
47 if (!found_custom && custom_value > min && custom_value < max) {
48 zoom_values.push_back(custom_value);
49 std::sort(zoom_values.begin(), zoom_values.end());
50 }
51 return zoom_values;
52 }
53
54 std::vector<double> PresetZoomFactors(double custom_factor) {
55 return PresetZoomValues(PAGE_ZOOM_VALUE_TYPE_FACTOR, custom_factor);
56 }
57
58 std::vector<double> PresetZoomLevels(double custom_level) {
59 return PresetZoomValues(PAGE_ZOOM_VALUE_TYPE_LEVEL, custom_level);
60 }
61
62 bool ZoomValuesEqual(double value_a, double value_b) {
63 // Epsilon value for comparing two floating-point zoom values. We don't use
64 // std::numeric_limits<> because it is too precise for zoom values. Zoom
65 // values loose precision due to factor/level conversions. A value of 0.001
66 // is precise enough for zoom value comparisons.
67 const double epsilon = 0.001;
68
69 return (std::fabs(value_a - value_b) <= epsilon);
70 }
71
72 } // namespace content
73
OLDNEW
« no previous file with comments | « content/public/common/page_zoom.h ('k') | content/public/common/page_zoom_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698