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

Side by Side Diff: ash/display/display_manager.cc

Issue 14710011: Redesign display options for ChromeOS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « ash/display/display_manager.h ('k') | chrome/app/chromeos_strings.grdp » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ash/display/display_manager.h" 5 #include "ash/display/display_manager.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 struct ScaleComparator { 79 struct ScaleComparator {
80 ScaleComparator(float s) : scale(s) {} 80 ScaleComparator(float s) : scale(s) {}
81 81
82 bool operator()(float s) const { 82 bool operator()(float s) const {
83 const float kEpsilon = 0.0001f; 83 const float kEpsilon = 0.0001f;
84 return std::abs(scale - s) < kEpsilon; 84 return std::abs(scale - s) < kEpsilon;
85 } 85 }
86 float scale; 86 float scale;
87 }; 87 };
88 88
89 std::vector<float> GetScalesForDisplay(const DisplayInfo& info) {
90 std::vector<float> ret;
91 if (info.device_scale_factor() == 2.0f) {
92 ret.assign(kUIScalesFor2x, kUIScalesFor2x + arraysize(kUIScalesFor2x));
93 return ret;
94 }
95 switch (info.bounds_in_pixel().width()) {
96 case 1280:
97 ret.assign(kUIScalesFor1280,
98 kUIScalesFor1280 + arraysize(kUIScalesFor1280));
99 break;
100 case 1366:
101 ret.assign(kUIScalesFor1366,
102 kUIScalesFor1366 + arraysize(kUIScalesFor1366));
103 break;
104 default:
105 ret.assign(kUIScalesFor1280,
106 kUIScalesFor1280 + arraysize(kUIScalesFor1280));
107 #if defined(OS_CHROMEOS)
108 if (base::chromeos::IsRunningOnChromeOS())
109 NOTREACHED() << "Unknown resolution:" << info.ToString();
110 #endif
111 }
112 return ret;
113 }
114
115 gfx::Display& GetInvalidDisplay() { 89 gfx::Display& GetInvalidDisplay() {
116 static gfx::Display* invalid_display = new gfx::Display(); 90 static gfx::Display* invalid_display = new gfx::Display();
117 return *invalid_display; 91 return *invalid_display;
118 } 92 }
119 93
120 } // namespace 94 } // namespace
121 95
122 using aura::RootWindow; 96 using aura::RootWindow;
123 using aura::Window; 97 using aura::Window;
124 using std::string; 98 using std::string;
(...skipping 11 matching lines...) Expand all
136 #if defined(OS_CHROMEOS) 110 #if defined(OS_CHROMEOS)
137 change_display_upon_host_resize_ = !base::chromeos::IsRunningOnChromeOS(); 111 change_display_upon_host_resize_ = !base::chromeos::IsRunningOnChromeOS();
138 #endif 112 #endif
139 Init(); 113 Init();
140 } 114 }
141 115
142 DisplayManager::~DisplayManager() { 116 DisplayManager::~DisplayManager() {
143 } 117 }
144 118
145 // static 119 // static
120 std::vector<float> DisplayManager::GetScalesForDisplay(
121 const DisplayInfo& info) {
122 std::vector<float> ret;
123 if (info.device_scale_factor() == 2.0f) {
124 ret.assign(kUIScalesFor2x, kUIScalesFor2x + arraysize(kUIScalesFor2x));
125 return ret;
126 }
127 switch (info.bounds_in_pixel().width()) {
128 case 1280:
129 ret.assign(kUIScalesFor1280,
130 kUIScalesFor1280 + arraysize(kUIScalesFor1280));
131 break;
132 case 1366:
133 ret.assign(kUIScalesFor1366,
134 kUIScalesFor1366 + arraysize(kUIScalesFor1366));
135 break;
136 default:
137 ret.assign(kUIScalesFor1280,
138 kUIScalesFor1280 + arraysize(kUIScalesFor1280));
139 #if defined(OS_CHROMEOS)
140 if (base::chromeos::IsRunningOnChromeOS())
141 NOTREACHED() << "Unknown resolution:" << info.ToString();
142 #endif
143 }
144 return ret;
145 }
146
147 // static
146 float DisplayManager::GetNextUIScale(const DisplayInfo& info, bool up) { 148 float DisplayManager::GetNextUIScale(const DisplayInfo& info, bool up) {
147 float scale = info.ui_scale(); 149 float scale = info.ui_scale();
148 std::vector<float> scales = GetScalesForDisplay(info); 150 std::vector<float> scales = GetScalesForDisplay(info);
149 for (size_t i = 0; i < scales.size(); ++i) { 151 for (size_t i = 0; i < scales.size(); ++i) {
150 if (ScaleComparator(scales[i])(scale)) { 152 if (ScaleComparator(scales[i])(scale)) {
151 if (up && i != scales.size() - 1) 153 if (up && i != scales.size() - 1)
152 return scales[i + 1]; 154 return scales[i + 1];
153 if (!up && i != 0) 155 if (!up && i != 0)
154 return scales[i - 1]; 156 return scales[i - 1];
155 return scales[i]; 157 return scales[i];
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 // always (0,0) and the secondary display's bounds will be updated 742 // always (0,0) and the secondary display's bounds will be updated
741 // by |DisplayController::UpdateDisplayBoundsForLayout|. 743 // by |DisplayController::UpdateDisplayBoundsForLayout|.
742 new_display.SetScaleAndBounds( 744 new_display.SetScaleAndBounds(
743 display_info.device_scale_factor(), gfx::Rect(bounds_in_pixel.size())); 745 display_info.device_scale_factor(), gfx::Rect(bounds_in_pixel.size()));
744 new_display.set_rotation(display_info.rotation()); 746 new_display.set_rotation(display_info.rotation());
745 return new_display; 747 return new_display;
746 } 748 }
747 749
748 } // namespace internal 750 } // namespace internal
749 } // namespace ash 751 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/display_manager.h ('k') | chrome/app/chromeos_strings.grdp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698