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

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

Issue 1197243004: Replace some Tokenize calls with SplitString. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix android Created 5 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 <stdio.h> 5 #include <stdio.h>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "ash/display/display_info.h" 9 #include "ash/display/display_info.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/string_split.h"
12 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
13 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
14 #include "ui/gfx/display.h" 15 #include "ui/gfx/display.h"
15 #include "ui/gfx/geometry/size_conversions.h" 16 #include "ui/gfx/geometry/size_conversions.h"
16 #include "ui/gfx/geometry/size_f.h" 17 #include "ui/gfx/geometry/size_f.h"
17 18
18 #if defined(OS_WIN) 19 #if defined(OS_WIN)
19 #include "ui/aura/window_tree_host.h" 20 #include "ui/aura/window_tree_host.h"
20 #include "ui/gfx/win/dpi.h" 21 #include "ui/gfx/win/dpi.h"
21 #endif 22 #endif
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 const int kDefaultHostWindowX = 200; 123 const int kDefaultHostWindowX = 200;
123 const int kDefaultHostWindowY = 200; 124 const int kDefaultHostWindowY = 200;
124 const int kDefaultHostWindowWidth = 1366; 125 const int kDefaultHostWindowWidth = 1366;
125 const int kDefaultHostWindowHeight = 768; 126 const int kDefaultHostWindowHeight = 768;
126 gfx::Rect bounds_in_native(kDefaultHostWindowX, kDefaultHostWindowY, 127 gfx::Rect bounds_in_native(kDefaultHostWindowX, kDefaultHostWindowY,
127 kDefaultHostWindowWidth, kDefaultHostWindowHeight); 128 kDefaultHostWindowWidth, kDefaultHostWindowHeight);
128 #endif 129 #endif
129 std::string main_spec = spec; 130 std::string main_spec = spec;
130 131
131 float ui_scale = 1.0f; 132 float ui_scale = 1.0f;
132 std::vector<std::string> parts; 133 std::vector<std::string> parts = base::SplitString(
133 if (Tokenize(main_spec, "@", &parts) == 2) { 134 main_spec, "@", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
135 if (parts.size() == 2) {
134 double scale_in_double = 0; 136 double scale_in_double = 0;
135 if (base::StringToDouble(parts[1], &scale_in_double)) 137 if (base::StringToDouble(parts[1], &scale_in_double))
136 ui_scale = scale_in_double; 138 ui_scale = scale_in_double;
137 main_spec = parts[0]; 139 main_spec = parts[0];
138 } 140 }
139 141
140 size_t count = Tokenize(main_spec, "/", &parts); 142 parts = base::SplitString(main_spec, "/", base::KEEP_WHITESPACE,
143 base::SPLIT_WANT_NONEMPTY);
141 gfx::Display::Rotation rotation(gfx::Display::ROTATE_0); 144 gfx::Display::Rotation rotation(gfx::Display::ROTATE_0);
142 bool has_overscan = false; 145 bool has_overscan = false;
143 if (count) { 146 if (!parts.empty()) {
144 main_spec = parts[0]; 147 main_spec = parts[0];
145 if (count >= 2) { 148 if (parts.size() >= 2) {
146 std::string options = parts[1]; 149 std::string options = parts[1];
147 for (size_t i = 0; i < options.size(); ++i) { 150 for (size_t i = 0; i < options.size(); ++i) {
148 char c = options[i]; 151 char c = options[i];
149 switch (c) { 152 switch (c) {
150 case 'o': 153 case 'o':
151 has_overscan = true; 154 has_overscan = true;
152 break; 155 break;
153 case 'r': // rotate 90 degrees to 'right'. 156 case 'r': // rotate 90 degrees to 'right'.
154 rotation = gfx::Display::ROTATE_90; 157 rotation = gfx::Display::ROTATE_90;
155 break; 158 break;
156 case 'u': // 180 degrees, 'u'pside-down. 159 case 'u': // 180 degrees, 'u'pside-down.
157 rotation = gfx::Display::ROTATE_180; 160 rotation = gfx::Display::ROTATE_180;
158 break; 161 break;
159 case 'l': // rotate 90 degrees to 'left'. 162 case 'l': // rotate 90 degrees to 'left'.
160 rotation = gfx::Display::ROTATE_270; 163 rotation = gfx::Display::ROTATE_270;
161 break; 164 break;
162 } 165 }
163 } 166 }
164 } 167 }
165 } 168 }
166 169
167 float device_scale_factor = 1.0f; 170 float device_scale_factor = 1.0f;
168 if (!GetDisplayBounds(main_spec, &bounds_in_native, &device_scale_factor)) { 171 if (!GetDisplayBounds(main_spec, &bounds_in_native, &device_scale_factor)) {
169 #if defined(OS_WIN) 172 #if defined(OS_WIN)
170 device_scale_factor = gfx::GetDPIScale(); 173 device_scale_factor = gfx::GetDPIScale();
171 #endif 174 #endif
172 } 175 }
173 176
174 std::vector<DisplayMode> display_modes; 177 std::vector<DisplayMode> display_modes;
175 if (Tokenize(main_spec, "#", &parts) == 2) { 178 parts = base::SplitString(main_spec, "#", base::KEEP_WHITESPACE,
179 base::SPLIT_WANT_NONEMPTY);
180 if (parts.size() == 2) {
176 size_t native_mode = 0; 181 size_t native_mode = 0;
177 int largest_area = -1; 182 int largest_area = -1;
178 float highest_refresh_rate = -1.0f; 183 float highest_refresh_rate = -1.0f;
179 main_spec = parts[0]; 184 main_spec = parts[0];
180 std::string resolution_list = parts[1]; 185 std::string resolution_list = parts[1];
181 count = Tokenize(resolution_list, "|", &parts); 186 parts = base::SplitString(resolution_list, "|", base::KEEP_WHITESPACE,
182 for (size_t i = 0; i < count; ++i) { 187 base::SPLIT_WANT_NONEMPTY);
188 for (size_t i = 0; i < parts.size(); ++i) {
183 DisplayMode mode; 189 DisplayMode mode;
184 gfx::Rect mode_bounds; 190 gfx::Rect mode_bounds;
185 std::vector<std::string> resolution; 191 std::vector<std::string> resolution = base::SplitString(
186 Tokenize(parts[i], "%", &resolution); 192 parts[i], "%", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
187 if (GetDisplayBounds( 193 if (GetDisplayBounds(
188 resolution[0], &mode_bounds, &mode.device_scale_factor)) { 194 resolution[0], &mode_bounds, &mode.device_scale_factor)) {
189 mode.size = mode_bounds.size(); 195 mode.size = mode_bounds.size();
190 if (resolution.size() > 1) 196 if (resolution.size() > 1)
191 sscanf(resolution[1].c_str(), "%f", &mode.refresh_rate); 197 sscanf(resolution[1].c_str(), "%f", &mode.refresh_rate);
192 if (mode.size.GetArea() >= largest_area && 198 if (mode.size.GetArea() >= largest_area &&
193 mode.refresh_rate > highest_refresh_rate) { 199 mode.refresh_rate > highest_refresh_rate) {
194 // Use mode with largest area and highest refresh rate as native. 200 // Use mode with largest area and highest refresh rate as native.
195 largest_area = mode.size.GetArea(); 201 largest_area = mode.size.GetArea();
196 highest_refresh_rate = mode.refresh_rate; 202 highest_refresh_rate = mode.refresh_rate;
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 return std::find(available_color_profiles_.begin(), 427 return std::find(available_color_profiles_.begin(),
422 available_color_profiles_.end(), 428 available_color_profiles_.end(),
423 profile) != available_color_profiles_.end(); 429 profile) != available_color_profiles_.end();
424 } 430 }
425 431
426 bool DisplayInfo::Use125DSFRorUIScaling() const { 432 bool DisplayInfo::Use125DSFRorUIScaling() const {
427 return use_125_dsf_for_ui_scaling && id_ == gfx::Display::InternalDisplayId(); 433 return use_125_dsf_for_ui_scaling && id_ == gfx::Display::InternalDisplayId();
428 } 434 }
429 435
430 } // namespace ash 436 } // namespace ash
OLDNEW
« no previous file with comments | « android_webview/browser/aw_media_client_android.cc ('k') | base/process/process_iterator_freebsd.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698