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

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

Issue 847703003: Refactor to move chrome_page_zoom functions to components/ui/zoom. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build. Created 5 years, 11 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
OLDNEW
1 // Copyright (c) 2012 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 "chrome/browser/chrome_page_zoom.h" 5 #include "components/ui/zoom/page_zoom.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "chrome/browser/chrome_page_zoom_constants.h" 11 #include "components/ui/zoom/page_zoom_constants.h"
12 #include "components/ui/zoom/zoom_controller.h" 12 #include "components/ui/zoom/zoom_controller.h"
13 #include "content/public/browser/host_zoom_map.h" 13 #include "content/public/browser/host_zoom_map.h"
14 #include "content/public/browser/render_view_host.h" 14 #include "content/public/browser/render_view_host.h"
15 #include "content/public/browser/user_metrics.h" 15 #include "content/public/browser/user_metrics.h"
16 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
17 #include "content/public/common/page_zoom.h" 17 #include "content/public/common/page_zoom.h"
18 #include "content/public/common/renderer_preferences.h" 18 #include "content/public/common/renderer_preferences.h"
19 19
20 using base::UserMetricsAction; 20 using base::UserMetricsAction;
21 21
22 namespace chrome_page_zoom { 22 namespace {
23 23
24 enum PageZoomValueType { 24 enum PageZoomValueType {
25 PAGE_ZOOM_VALUE_TYPE_FACTOR, 25 PAGE_ZOOM_VALUE_TYPE_FACTOR,
26 PAGE_ZOOM_VALUE_TYPE_LEVEL, 26 PAGE_ZOOM_VALUE_TYPE_LEVEL,
27 }; 27 };
28 28
29 std::vector<double> PresetZoomValues(PageZoomValueType value_type, 29 std::vector<double> PresetZoomValues(PageZoomValueType value_type,
30 double custom_value) { 30 double custom_value) {
31 // Generate a vector of zoom values from an array of known preset 31 // Generate a vector of zoom values from an array of known preset
32 // factors. The values in content::kPresetZoomFactors will already be in 32 // factors. The values in content::kPresetZoomFactors will already be in
33 // sorted order. 33 // sorted order.
34 std::vector<double> zoom_values; 34 std::vector<double> zoom_values;
35 bool found_custom = false; 35 bool found_custom = false;
36 for (size_t i = 0; i < kPresetZoomFactorsSize; i++) { 36 for (size_t i = 0; i < ui_zoom::kPresetZoomFactorsSize; i++) {
37 double zoom_value = kPresetZoomFactors[i]; 37 double zoom_value = ui_zoom::kPresetZoomFactors[i];
38 if (value_type == PAGE_ZOOM_VALUE_TYPE_LEVEL) 38 if (value_type == PAGE_ZOOM_VALUE_TYPE_LEVEL)
39 zoom_value = content::ZoomFactorToZoomLevel(zoom_value); 39 zoom_value = content::ZoomFactorToZoomLevel(zoom_value);
40 if (content::ZoomValuesEqual(zoom_value, custom_value)) 40 if (content::ZoomValuesEqual(zoom_value, custom_value))
41 found_custom = true; 41 found_custom = true;
42 zoom_values.push_back(zoom_value); 42 zoom_values.push_back(zoom_value);
43 } 43 }
44 // If the preset array did not contain the custom value, append it to the 44 // If the preset array did not contain the custom value, append it to the
45 // vector and then sort. 45 // vector and then sort.
46 double min = value_type == PAGE_ZOOM_VALUE_TYPE_LEVEL ? 46 double min = value_type == PAGE_ZOOM_VALUE_TYPE_LEVEL ?
47 content::ZoomFactorToZoomLevel(content::kMinimumZoomFactor) : 47 content::ZoomFactorToZoomLevel(content::kMinimumZoomFactor) :
48 content::kMinimumZoomFactor; 48 content::kMinimumZoomFactor;
49 double max = value_type == PAGE_ZOOM_VALUE_TYPE_LEVEL ? 49 double max = value_type == PAGE_ZOOM_VALUE_TYPE_LEVEL ?
50 content::ZoomFactorToZoomLevel(content::kMaximumZoomFactor) : 50 content::ZoomFactorToZoomLevel(content::kMaximumZoomFactor) :
51 content::kMaximumZoomFactor; 51 content::kMaximumZoomFactor;
52 if (!found_custom && custom_value > min && custom_value < max) { 52 if (!found_custom && custom_value > min && custom_value < max) {
53 zoom_values.push_back(custom_value); 53 zoom_values.push_back(custom_value);
54 std::sort(zoom_values.begin(), zoom_values.end()); 54 std::sort(zoom_values.begin(), zoom_values.end());
55 } 55 }
56 return zoom_values; 56 return zoom_values;
57 } 57 }
58 58
59 std::vector<double> PresetZoomFactors(double custom_factor) { 59 } // namespace anonymous
60
61 namespace ui_zoom {
62
63 // Static.
Fady Samuel 2015/01/14 17:38:15 nit: lowercase and no period // static
wjmaclean 2015/01/14 17:56:49 Done.
64 std::vector<double> PageZoom::PresetZoomFactors(double custom_factor) {
60 return PresetZoomValues(PAGE_ZOOM_VALUE_TYPE_FACTOR, custom_factor); 65 return PresetZoomValues(PAGE_ZOOM_VALUE_TYPE_FACTOR, custom_factor);
61 } 66 }
62 67
63 std::vector<double> PresetZoomLevels(double custom_level) { 68 // Static.
Fady Samuel 2015/01/14 17:38:15 nit: // static
69 std::vector<double> PageZoom::PresetZoomLevels(double custom_level) {
64 return PresetZoomValues(PAGE_ZOOM_VALUE_TYPE_LEVEL, custom_level); 70 return PresetZoomValues(PAGE_ZOOM_VALUE_TYPE_LEVEL, custom_level);
65 } 71 }
66 72
67 void Zoom(content::WebContents* web_contents, content::PageZoom zoom) { 73 // Static.
Fady Samuel 2015/01/14 17:38:14 nit: // static
74 void PageZoom::Zoom(content::WebContents* web_contents,
75 content::PageZoom zoom) {
68 ui_zoom::ZoomController* zoom_controller = 76 ui_zoom::ZoomController* zoom_controller =
69 ui_zoom::ZoomController::FromWebContents(web_contents); 77 ui_zoom::ZoomController::FromWebContents(web_contents);
70 DCHECK(zoom_controller); 78 DCHECK(zoom_controller);
71 79
72 double current_zoom_level = zoom_controller->GetZoomLevel(); 80 double current_zoom_level = zoom_controller->GetZoomLevel();
73 double default_zoom_level = zoom_controller->GetDefaultZoomLevel(); 81 double default_zoom_level = zoom_controller->GetDefaultZoomLevel();
74 82
75 if (zoom == content::PAGE_ZOOM_RESET) { 83 if (zoom == content::PAGE_ZOOM_RESET) {
76 zoom_controller->SetZoomLevel(default_zoom_level); 84 zoom_controller->SetZoomLevel(default_zoom_level);
77 content::RecordAction(UserMetricsAction("ZoomNormal")); 85 content::RecordAction(UserMetricsAction("ZoomNormal"));
(...skipping 30 matching lines...) Expand all
108 if (zoom_level > current_zoom_level) { 116 if (zoom_level > current_zoom_level) {
109 zoom_controller->SetZoomLevel(zoom_level); 117 zoom_controller->SetZoomLevel(zoom_level);
110 content::RecordAction(UserMetricsAction("ZoomPlus")); 118 content::RecordAction(UserMetricsAction("ZoomPlus"));
111 return; 119 return;
112 } 120 }
113 } 121 }
114 content::RecordAction(UserMetricsAction("ZoomPlus_AtMaximum")); 122 content::RecordAction(UserMetricsAction("ZoomPlus_AtMaximum"));
115 } 123 }
116 } 124 }
117 125
118 } // namespace chrome_page_zoom 126 } // namespace ui_zoom
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698