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

Side by Side Diff: components/zoom/page_zoom.cc

Issue 2019423005: Move //components/ui/zoom to top-level under //components (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 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
« no previous file with comments | « components/zoom/page_zoom.h ('k') | components/zoom/page_zoom_constants.h » ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/ui/zoom/page_zoom.h" 5 #include "components/zoom/page_zoom.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cmath> 10 #include <cmath>
11 11
12 #include "components/prefs/pref_service.h" 12 #include "components/prefs/pref_service.h"
13 #include "components/ui/zoom/page_zoom_constants.h" 13 #include "components/zoom/page_zoom_constants.h"
14 #include "components/ui/zoom/zoom_controller.h" 14 #include "components/zoom/zoom_controller.h"
15 #include "content/public/browser/host_zoom_map.h" 15 #include "content/public/browser/host_zoom_map.h"
16 #include "content/public/browser/render_view_host.h" 16 #include "content/public/browser/render_view_host.h"
17 #include "content/public/browser/user_metrics.h" 17 #include "content/public/browser/user_metrics.h"
18 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
19 #include "content/public/common/page_zoom.h" 19 #include "content/public/common/page_zoom.h"
20 #include "content/public/common/renderer_preferences.h" 20 #include "content/public/common/renderer_preferences.h"
21 21
22 using base::UserMetricsAction; 22 using base::UserMetricsAction;
23 23
24 namespace { 24 namespace {
25 25
26 enum PageZoomValueType { 26 enum PageZoomValueType {
27 PAGE_ZOOM_VALUE_TYPE_FACTOR, 27 PAGE_ZOOM_VALUE_TYPE_FACTOR,
28 PAGE_ZOOM_VALUE_TYPE_LEVEL, 28 PAGE_ZOOM_VALUE_TYPE_LEVEL,
29 }; 29 };
30 30
31 std::vector<double> PresetZoomValues(PageZoomValueType value_type, 31 std::vector<double> PresetZoomValues(PageZoomValueType value_type,
32 double custom_value) { 32 double custom_value) {
33 // Generate a vector of zoom values from an array of known preset 33 // Generate a vector of zoom values from an array of known preset
34 // factors. The values in content::kPresetZoomFactors will already be in 34 // factors. The values in content::kPresetZoomFactors will already be in
35 // sorted order. 35 // sorted order.
36 std::vector<double> zoom_values; 36 std::vector<double> zoom_values;
37 bool found_custom = false; 37 bool found_custom = false;
38 for (size_t i = 0; i < ui_zoom::kPresetZoomFactorsSize; i++) { 38 for (size_t i = 0; i < zoom::kPresetZoomFactorsSize; i++) {
39 double zoom_value = ui_zoom::kPresetZoomFactors[i]; 39 double zoom_value = zoom::kPresetZoomFactors[i];
40 if (value_type == PAGE_ZOOM_VALUE_TYPE_LEVEL) 40 if (value_type == PAGE_ZOOM_VALUE_TYPE_LEVEL)
41 zoom_value = content::ZoomFactorToZoomLevel(zoom_value); 41 zoom_value = content::ZoomFactorToZoomLevel(zoom_value);
42 if (content::ZoomValuesEqual(zoom_value, custom_value)) 42 if (content::ZoomValuesEqual(zoom_value, custom_value))
43 found_custom = true; 43 found_custom = true;
44 zoom_values.push_back(zoom_value); 44 zoom_values.push_back(zoom_value);
45 } 45 }
46 // If the preset array did not contain the custom value, append it to the 46 // If the preset array did not contain the custom value, append it to the
47 // vector and then sort. 47 // vector and then sort.
48 double min = value_type == PAGE_ZOOM_VALUE_TYPE_LEVEL ? 48 double min = value_type == PAGE_ZOOM_VALUE_TYPE_LEVEL
49 content::ZoomFactorToZoomLevel(content::kMinimumZoomFactor) : 49 ? content::ZoomFactorToZoomLevel(content::kMinimumZoomFactor)
50 content::kMinimumZoomFactor; 50 : content::kMinimumZoomFactor;
51 double max = value_type == PAGE_ZOOM_VALUE_TYPE_LEVEL ? 51 double max = value_type == PAGE_ZOOM_VALUE_TYPE_LEVEL
52 content::ZoomFactorToZoomLevel(content::kMaximumZoomFactor) : 52 ? content::ZoomFactorToZoomLevel(content::kMaximumZoomFactor)
53 content::kMaximumZoomFactor; 53 : content::kMaximumZoomFactor;
54 if (!found_custom && custom_value > min && custom_value < max) { 54 if (!found_custom && custom_value > min && custom_value < max) {
55 zoom_values.push_back(custom_value); 55 zoom_values.push_back(custom_value);
56 std::sort(zoom_values.begin(), zoom_values.end()); 56 std::sort(zoom_values.begin(), zoom_values.end());
57 } 57 }
58 return zoom_values; 58 return zoom_values;
59 } 59 }
60 60
61 } // namespace anonymous 61 } // namespace anonymous
62 62
63 namespace ui_zoom { 63 namespace zoom {
64 64
65 // static 65 // static
66 std::vector<double> PageZoom::PresetZoomFactors(double custom_factor) { 66 std::vector<double> PageZoom::PresetZoomFactors(double custom_factor) {
67 return PresetZoomValues(PAGE_ZOOM_VALUE_TYPE_FACTOR, custom_factor); 67 return PresetZoomValues(PAGE_ZOOM_VALUE_TYPE_FACTOR, custom_factor);
68 } 68 }
69 69
70 // static 70 // static
71 std::vector<double> PageZoom::PresetZoomLevels(double custom_level) { 71 std::vector<double> PageZoom::PresetZoomLevels(double custom_level) {
72 return PresetZoomValues(PAGE_ZOOM_VALUE_TYPE_LEVEL, custom_level); 72 return PresetZoomValues(PAGE_ZOOM_VALUE_TYPE_LEVEL, custom_level);
73 } 73 }
74 74
75 // static 75 // static
76 void PageZoom::Zoom(content::WebContents* web_contents, 76 void PageZoom::Zoom(content::WebContents* web_contents,
77 content::PageZoom zoom) { 77 content::PageZoom zoom) {
78 ui_zoom::ZoomController* zoom_controller = 78 zoom::ZoomController* zoom_controller =
79 ui_zoom::ZoomController::FromWebContents(web_contents); 79 zoom::ZoomController::FromWebContents(web_contents);
80 if (!zoom_controller) 80 if (!zoom_controller)
81 return; 81 return;
82 82
83 double current_zoom_level = zoom_controller->GetZoomLevel(); 83 double current_zoom_level = zoom_controller->GetZoomLevel();
84 double default_zoom_level = zoom_controller->GetDefaultZoomLevel(); 84 double default_zoom_level = zoom_controller->GetDefaultZoomLevel();
85 85
86 if (zoom == content::PAGE_ZOOM_RESET) { 86 if (zoom == content::PAGE_ZOOM_RESET) {
87 zoom_controller->SetZoomLevel(default_zoom_level); 87 zoom_controller->SetZoomLevel(default_zoom_level);
88 web_contents->SetPageScale(1.f); 88 web_contents->SetPageScale(1.f);
89 content::RecordAction(UserMetricsAction("ZoomNormal")); 89 content::RecordAction(UserMetricsAction("ZoomNormal"));
(...skipping 30 matching lines...) Expand all
120 if (zoom_level > current_zoom_level) { 120 if (zoom_level > current_zoom_level) {
121 zoom_controller->SetZoomLevel(zoom_level); 121 zoom_controller->SetZoomLevel(zoom_level);
122 content::RecordAction(UserMetricsAction("ZoomPlus")); 122 content::RecordAction(UserMetricsAction("ZoomPlus"));
123 return; 123 return;
124 } 124 }
125 } 125 }
126 content::RecordAction(UserMetricsAction("ZoomPlus_AtMaximum")); 126 content::RecordAction(UserMetricsAction("ZoomPlus_AtMaximum"));
127 } 127 }
128 } 128 }
129 129
130 } // namespace ui_zoom 130 } // namespace zoom
OLDNEW
« no previous file with comments | « components/zoom/page_zoom.h ('k') | components/zoom/page_zoom_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698