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

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: Minor cleanups 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
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 const double kMinimumZoomFactor = 0.25;
13 const double kMaximumZoomFactor = 5.0;
14
15 const double kPresetZoomFactors[] = { 0.25, 0.333, 0.5, 0.666, 0.75, 0.9, 1.0,
16 1.1, 1.25, 1.5, 1.75, 2.0, 2.5, 3.0, 4.0,
17 5.0 };
18
19 std::vector<double> PageZoomHelpers::PresetFactorsWithCustomValue(
20 double custom_factor) {
21 return PresetValuesWithCustomValue(PAGE_ZOOM_VALUE_TYPE_FACTOR,
22 custom_factor);
23 }
24
25 std::vector<double> PageZoomHelpers::PresetLevelsWithCustomValue(
26 double custom_level) {
27 return PresetValuesWithCustomValue(
28 PageZoomHelpers::PAGE_ZOOM_VALUE_TYPE_LEVEL, custom_level);
29 }
30
31 std::vector<double> PageZoomHelpers::PresetValuesWithCustomValue(
32 PageZoomHelpers::PageZoomValueType value_type, double custom_value) {
33 // Generate a vector of zoom values from an array of known preset
34 // factors. The values in content::kPresetZoomFactors will already be in
35 // sorted order.
36 std::vector<double> zoom_values;
37 bool found_default = false;
38 for (size_t i = 0; i < arraysize(kPresetZoomFactors); i++) {
39 double zoom_value = content::kPresetZoomFactors[i];
40 if (value_type == PageZoomHelpers::PAGE_ZOOM_VALUE_TYPE_LEVEL)
41 zoom_value = WebKit::WebView::zoomFactorToZoomLevel(zoom_value);
42 if (ZoomValuesEqual(zoom_value, custom_value))
43 found_default = true;
44 zoom_values.push_back(zoom_value);
45 }
46 // If the preset array did not contain the custom value, append it to the
47 // vector and then sort.
48 if (!found_default) {
49 zoom_values.push_back(custom_value);
50 std::sort(zoom_values.begin(), zoom_values.end());
51 }
52 return zoom_values;
53 }
54
55 bool PageZoomHelpers::ZoomValuesEqual(double value_a, double value_b) {
56 // Epsilon value for comparing two floating-point zoom values. We don't use
57 // std::numeric_limits<> because it is too precise for zoom values. Zoom
58 // values loose precision due to factor/level conversions. A value of 0.001
59 // is precise enough for zoom value comparisons.
60 const double epsilon = 0.001;
61
62 return (std::fabs(value_a - value_b) <= epsilon);
63 }
64
65 } // namespace content
66
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698