OLD | NEW |
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 <algorithm> | 5 #include "chrome/browser/chrome_page_zoom_constants.h" |
6 #include <cmath> | |
7 | |
8 #include "chrome/browser/chrome_page_zoom.h" | |
9 #include "content/public/common/page_zoom.h" | |
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | |
11 | 6 |
12 namespace chrome_page_zoom { | 7 namespace chrome_page_zoom { |
13 | 8 |
14 enum PageZoomValueType { | |
15 PAGE_ZOOM_VALUE_TYPE_FACTOR, | |
16 PAGE_ZOOM_VALUE_TYPE_LEVEL, | |
17 }; | |
18 | |
19 const double kPresetZoomFactors[] = { 0.25, 0.333, 0.5, 0.666, 0.75, 0.9, 1.0, | 9 const double kPresetZoomFactors[] = { 0.25, 0.333, 0.5, 0.666, 0.75, 0.9, 1.0, |
20 1.1, 1.25, 1.5, 1.75, 2.0, 2.5, 3.0, 4.0, | 10 1.1, 1.25, 1.5, 1.75, 2.0, 2.5, 3.0, 4.0, |
21 5.0 }; | 11 5.0 }; |
22 const size_t kPresetZoomFactorsSize = arraysize(kPresetZoomFactors); | 12 const size_t kPresetZoomFactorsSize = arraysize(kPresetZoomFactors); |
23 | 13 |
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 < kPresetZoomFactorsSize; i++) { | |
32 double zoom_value = kPresetZoomFactors[i]; | |
33 if (value_type == PAGE_ZOOM_VALUE_TYPE_LEVEL) | |
34 zoom_value = WebKit::WebView::zoomFactorToZoomLevel(zoom_value); | |
35 if (content::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(content::kMinimumZoomFactor) : | |
43 content::kMinimumZoomFactor; | |
44 double max = value_type == PAGE_ZOOM_VALUE_TYPE_LEVEL ? | |
45 WebKit::WebView::zoomFactorToZoomLevel(content::kMaximumZoomFactor) : | |
46 content::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 } // namespace chrome_page_zoom | 14 } // namespace chrome_page_zoom |
OLD | NEW |