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

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
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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 struct ScaleComparator { 78 struct ScaleComparator {
79 ScaleComparator(float s) : scale(s) {} 79 ScaleComparator(float s) : scale(s) {}
80 80
81 bool operator()(float s) const { 81 bool operator()(float s) const {
82 const float kEpsilon = 0.0001f; 82 const float kEpsilon = 0.0001f;
83 return std::abs(scale - s) < kEpsilon; 83 return std::abs(scale - s) < kEpsilon;
84 } 84 }
85 float scale; 85 float scale;
86 }; 86 };
87 87
88 std::vector<float> GetScalesForDisplay(const DisplayInfo& info) {
89 std::vector<float> ret;
90 if (info.device_scale_factor() == 2.0f) {
91 ret.assign(kUIScalesFor2x, kUIScalesFor2x + arraysize(kUIScalesFor2x));
92 return ret;
93 }
94 switch (info.bounds_in_pixel().width()) {
95 case 1280:
96 ret.assign(kUIScalesFor1280,
97 kUIScalesFor1280 + arraysize(kUIScalesFor1280));
98 break;
99 case 1366:
100 ret.assign(kUIScalesFor1366,
101 kUIScalesFor1366 + arraysize(kUIScalesFor1366));
102 break;
103 default:
104 ret.assign(kUIScalesFor1280,
105 kUIScalesFor1280 + arraysize(kUIScalesFor1280));
106 #if defined(OS_CHROMEOS)
107 if (base::chromeos::IsRunningOnChromeOS())
108 NOTREACHED() << "Unknown resolution:" << info.ToString();
109 #endif
110 }
111 return ret;
112 }
113
114 gfx::Display& GetInvalidDisplay() { 88 gfx::Display& GetInvalidDisplay() {
115 static gfx::Display* invalid_display = new gfx::Display(); 89 static gfx::Display* invalid_display = new gfx::Display();
116 return *invalid_display; 90 return *invalid_display;
117 } 91 }
118 92
119 } // namespace 93 } // namespace
120 94
121 using aura::RootWindow; 95 using aura::RootWindow;
122 using aura::Window; 96 using aura::Window;
123 using std::string; 97 using std::string;
(...skipping 21 matching lines...) Expand all
145 void DisplayManager::CycleDisplay() { 119 void DisplayManager::CycleDisplay() {
146 Shell::GetInstance()->display_manager()->CycleDisplayImpl(); 120 Shell::GetInstance()->display_manager()->CycleDisplayImpl();
147 } 121 }
148 122
149 // static 123 // static
150 void DisplayManager::ToggleDisplayScaleFactor() { 124 void DisplayManager::ToggleDisplayScaleFactor() {
151 Shell::GetInstance()->display_manager()->ScaleDisplayImpl(); 125 Shell::GetInstance()->display_manager()->ScaleDisplayImpl();
152 } 126 }
153 127
154 // static 128 // static
129 std::vector<float> DisplayManager::GetScalesForDisplay(
130 const DisplayInfo& info) {
131 std::vector<float> ret;
132 if (info.device_scale_factor() == 2.0f) {
133 ret.assign(kUIScalesFor2x, kUIScalesFor2x + arraysize(kUIScalesFor2x));
134 return ret;
135 }
136 switch (info.bounds_in_pixel().width()) {
137 case 1280:
138 ret.assign(kUIScalesFor1280,
139 kUIScalesFor1280 + arraysize(kUIScalesFor1280));
140 break;
141 case 1366:
142 ret.assign(kUIScalesFor1366,
143 kUIScalesFor1366 + arraysize(kUIScalesFor1366));
144 break;
145 default:
146 ret.assign(kUIScalesFor1280,
147 kUIScalesFor1280 + arraysize(kUIScalesFor1280));
148 #if defined(OS_CHROMEOS)
149 if (base::chromeos::IsRunningOnChromeOS())
150 NOTREACHED() << "Unknown resolution:" << info.ToString();
151 #endif
152 }
153 return ret;
154 }
155
156 // static
155 float DisplayManager::GetNextUIScale(const DisplayInfo& info, bool up) { 157 float DisplayManager::GetNextUIScale(const DisplayInfo& info, bool up) {
156 float scale = info.ui_scale(); 158 float scale = info.ui_scale();
157 std::vector<float> scales = GetScalesForDisplay(info); 159 std::vector<float> scales = GetScalesForDisplay(info);
158 for (size_t i = 0; i < scales.size(); ++i) { 160 for (size_t i = 0; i < scales.size(); ++i) {
159 if (ScaleComparator(scales[i])(scale)) { 161 if (ScaleComparator(scales[i])(scale)) {
160 if (up && i != scales.size() - 1) 162 if (up && i != scales.size() - 1)
161 return scales[i + 1]; 163 return scales[i + 1];
162 if (!up && i != 0) 164 if (!up && i != 0)
163 return scales[i - 1]; 165 return scales[i - 1];
164 return scales[i]; 166 return scales[i];
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 // always (0,0) and the secondary display's bounds will be updated 736 // always (0,0) and the secondary display's bounds will be updated
735 // by |DisplayController::UpdateDisplayBoundsForLayout|. 737 // by |DisplayController::UpdateDisplayBoundsForLayout|.
736 new_display.SetScaleAndBounds( 738 new_display.SetScaleAndBounds(
737 display_info.device_scale_factor(), gfx::Rect(bounds_in_pixel.size())); 739 display_info.device_scale_factor(), gfx::Rect(bounds_in_pixel.size()));
738 new_display.set_rotation(display_info.rotation()); 740 new_display.set_rotation(display_info.rotation());
739 return new_display; 741 return new_display;
740 } 742 }
741 743
742 } // namespace internal 744 } // namespace internal
743 } // namespace ash 745 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698