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

Unified Diff: chrome/browser/ui/webui/options/chromeos/display_options_handler.cc

Issue 227593011: Modifies the threshold for hidpi displays. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/options/chromeos/display_options_handler.cc
diff --git a/chrome/browser/ui/webui/options/chromeos/display_options_handler.cc b/chrome/browser/ui/webui/options/chromeos/display_options_handler.cc
index e4f6c0d1b9819c285d8585d9186cb2ecdd316b22..164d23423b75021b91c11c37c7009583c778ebaa 100644
--- a/chrome/browser/ui/webui/options/chromeos/display_options_handler.cc
+++ b/chrome/browser/ui/webui/options/chromeos/display_options_handler.cc
@@ -54,10 +54,33 @@ int64 GetDisplayId(const base::ListValue* args) {
return display_id;
}
-bool CompareDisplayMode(ash::DisplayMode d1, ash::DisplayMode d2) {
- if (d1.size.GetArea() == d2.size.GetArea())
- return d1.refresh_rate < d2.refresh_rate;
- return d1.size.GetArea() < d2.size.GetArea();
+bool CompareDisplayMode(base::Value* display1, base::Value* display2) {
+ base::DictionaryValue* d1 = NULL;
+ base::DictionaryValue* d2 = NULL;
+ CHECK(display1->GetAsDictionary(&d1) && display2->GetAsDictionary(&d2));
+ int w1 = 0, h1 = 0, w2 = 0, h2 = 0;
+ CHECK(d1->GetInteger("width", &w1) && d1->GetInteger("height", &h1));
+ CHECK(d2->GetInteger("width", &w2) && d2->GetInteger("height", &h2));
+ double sf1 = 0, sf2 = 0;
+ if (d1->GetDouble("scaleFactor", &sf1)) {
+ w1 /= sf1;
+ h1 /= sf1;
+ }
+ if (d2->GetDouble("scaleFactor", &sf2)) {
+ w2 /= sf2;
+ h2 /= sf2;
+ }
+
+ if (w1 * h1 == w2 * h2) {
+ if (sf1 != sf2)
+ return sf1 < sf2;
+
+ int r1 = 0, r2 = 0;
+ CHECK(d1->GetInteger("refreshRate", &r1) ==
+ d2->GetInteger("refreshRate", &r2));
+ return r1 < r2;
+ }
+ return w1 * h1 < w2 * h2;
}
base::string16 GetColorProfileName(ui::ColorCalibrationProfile profile) {
@@ -217,10 +240,11 @@ void DisplayOptionsHandler::SendDisplayInfo(
js_display->SetBoolean("isInternal", display.IsInternal());
js_display->SetInteger("orientation",
static_cast<int>(display_info.rotation()));
- std::vector<ash::DisplayMode> display_modes;
- std::vector<float> ui_scales;
+
+ base::ListValue* js_resolutions = new base::ListValue();
if (display.IsInternal()) {
- ui_scales = DisplayManager::GetScalesForDisplay(display_info);
+ const std::vector<float> ui_scales =
+ DisplayManager::GetScalesForDisplay(display_info);
gfx::SizeF base_size = display_info.bounds_in_native().size();
base_size.Scale(1.0f / display_info.device_scale_factor());
if (display_info.rotation() == gfx::Display::ROTATE_90 ||
@@ -230,46 +254,58 @@ void DisplayOptionsHandler::SendDisplayInfo(
base_size.set_height(tmp);
}
for (size_t i = 0; i < ui_scales.size(); ++i) {
+ base::DictionaryValue* resolution_info = new base::DictionaryValue();
gfx::SizeF new_size = base_size;
new_size.Scale(ui_scales[i]);
- display_modes.push_back(ash::DisplayMode(
- gfx::ToFlooredSize(new_size), -1.0f, false, false));
- }
- } else {
- for (size_t i = 0; i < display_info.display_modes().size(); ++i)
- display_modes.push_back(display_info.display_modes()[i]);
- }
- std::sort(display_modes.begin(), display_modes.end(), CompareDisplayMode);
-
- base::ListValue* js_resolutions = new base::ListValue();
- gfx::Size current_size = display_info.bounds_in_native().size();
- gfx::Insets current_overscan = display_info.GetOverscanInsetsInPixel();
- for (size_t i = 0; i < display_modes.size(); ++i) {
- base::DictionaryValue* resolution_info = new base::DictionaryValue();
- gfx::Size resolution = display_modes[i].size;
- if (!ui_scales.empty()) {
+ gfx::Size resolution = gfx::ToFlooredSize(new_size);
resolution_info->SetDouble("scale", ui_scales[i]);
if (ui_scales[i] == 1.0f)
resolution_info->SetBoolean("isBest", true);
resolution_info->SetBoolean(
"selected", display_info.configured_ui_scale() == ui_scales[i]);
- } else {
- // Picks the largest one as the "best", which is the last element
- // because |display_modes| is sorted by its area.
- if (i == display_modes.size() - 1)
+ resolution_info->SetInteger("width", resolution.width());
+ resolution_info->SetInteger("height", resolution.height());
+ js_resolutions->Append(resolution_info);
+ }
+ } else {
+ gfx::Size current_size = display_info.bounds_in_native().size();
oshima 2014/04/08 23:07:43 would you mind refacotring this define a method th
Jun Mukai 2014/04/09 20:20:07 Done.
+ gfx::Insets current_overscan = display_info.GetOverscanInsetsInPixel();
+ int largest_index = -1;
+ int largest_area = -1;
+ for (size_t i = 0; i < display_info.display_modes().size(); ++i) {
+ base::DictionaryValue* resolution_info = new base::DictionaryValue();
+ const ash::DisplayMode& display_mode = display_info.display_modes()[i];
+ gfx::Size resolution = display_mode.size;
+
+ if (resolution.GetArea() > largest_area) {
resolution_info->SetBoolean("isBest", true);
- resolution_info->SetBoolean("selected", (resolution == current_size));
+ largest_area = resolution.GetArea();
+ if (largest_index >= 0) {
+ base::DictionaryValue* prev_largest = NULL;
+ CHECK(js_resolutions->GetDictionary(largest_index, &prev_largest));
+ prev_largest->SetBoolean("isBest", false);
+ }
+ largest_index = i;
+ }
+ if (resolution == current_size) {
+ // Right now, the scale factor for unselected resolutions is unknown.
+ // TODO(mukai): Set the scale factor for unselected ones.
+ resolution_info->SetDouble(
+ "scaleFactor", display_info.device_scale_factor());
+ resolution_info->SetBoolean("selected", true);
+ } else {
+ resolution_info->SetBoolean("selected", false);
+ }
resolution.Enlarge(
-current_overscan.width(), -current_overscan.height());
+ resolution_info->SetInteger("width", resolution.width());
+ resolution_info->SetInteger("height", resolution.height());
+ resolution_info->SetDouble("refreshRate", display_mode.refresh_rate);
+ js_resolutions->Append(resolution_info);
}
- resolution_info->SetInteger("width", resolution.width());
- resolution_info->SetInteger("height", resolution.height());
- if (display_modes[i].refresh_rate > 0.0f) {
- resolution_info->SetDouble("refreshRate",
- display_modes[i].refresh_rate);
- }
- js_resolutions->Append(resolution_info);
}
+ std::sort(
+ js_resolutions->begin(), js_resolutions->end(), CompareDisplayMode);
js_display->Set("resolutions", js_resolutions);
js_display->SetInteger("colorProfile", display_info.color_profile());

Powered by Google App Engine
This is Rietveld 408576698