| 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 9dad1573658c9de6b97e0d8afe173d3f6cc014f7..8861b50a14b5e416042e6309bdaa89e2b5e16811 100644
|
| --- a/chrome/browser/ui/webui/options/chromeos/display_options_handler.cc
|
| +++ b/chrome/browser/ui/webui/options/chromeos/display_options_handler.cc
|
| @@ -23,8 +23,8 @@
|
| #include "ui/base/l10n/l10n_util.h"
|
| #include "ui/gfx/display.h"
|
| #include "ui/gfx/rect.h"
|
| -#include "ui/gfx/safe_integer_conversions.h"
|
| #include "ui/gfx/screen.h"
|
| +#include "ui/gfx/size_conversions.h"
|
|
|
| using ash::internal::DisplayManager;
|
|
|
| @@ -53,6 +53,11 @@ int64 GetDisplayId(const base::ListValue* args) {
|
| return display_id;
|
| }
|
|
|
| +bool CompareResolution(ash::internal::Resolution r1,
|
| + ash::internal::Resolution r2) {
|
| + return r1.size.GetArea() < r2.size.GetArea();
|
| +}
|
| +
|
| } // namespace
|
|
|
| DisplayOptionsHandler::DisplayOptionsHandler() {
|
| @@ -131,6 +136,10 @@ void DisplayOptionsHandler::RegisterMessages() {
|
| base::Bind(&DisplayOptionsHandler::HandleSetUIScale,
|
| base::Unretained(this)));
|
| web_ui()->RegisterMessageCallback(
|
| + "setResolution",
|
| + base::Bind(&DisplayOptionsHandler::HandleSetResolution,
|
| + base::Unretained(this)));
|
| + web_ui()->RegisterMessageCallback(
|
| "setOrientation",
|
| base::Bind(&DisplayOptionsHandler::HandleSetOrientation,
|
| base::Unretained(this)));
|
| @@ -179,30 +188,54 @@ void DisplayOptionsHandler::SendDisplayInfo(
|
| js_display->SetBoolean("isInternal", display.IsInternal());
|
| js_display->SetInteger("orientation",
|
| static_cast<int>(display_info.rotation()));
|
| - std::vector<float> ui_scales = DisplayManager::GetScalesForDisplay(
|
| - display_info);
|
| - base::ListValue* js_scales = new base::ListValue();
|
| - gfx::SizeF base_size = display_info.bounds_in_pixel().size();
|
| - base_size.Scale(1.0f / display.device_scale_factor());
|
| - if (display_info.rotation() == gfx::Display::ROTATE_90 ||
|
| - display_info.rotation() == gfx::Display::ROTATE_270) {
|
| - float tmp = base_size.width();
|
| - base_size.set_width(base_size.height());
|
| - base_size.set_height(tmp);
|
| + std::vector<ash::internal::Resolution> resolutions;
|
| + std::vector<float> ui_scales;
|
| + if (display.IsInternal()) {
|
| + ui_scales = DisplayManager::GetScalesForDisplay(display_info);
|
| + gfx::SizeF base_size = display_info.bounds_in_pixel().size();
|
| + base_size.Scale(1.0f / display.device_scale_factor());
|
| + if (display_info.rotation() == gfx::Display::ROTATE_90 ||
|
| + display_info.rotation() == gfx::Display::ROTATE_270) {
|
| + float tmp = base_size.width();
|
| + base_size.set_width(base_size.height());
|
| + base_size.set_height(tmp);
|
| + }
|
| + for (size_t i = 0; i < ui_scales.size(); ++i) {
|
| + gfx::SizeF new_size = base_size;
|
| + new_size.Scale(ui_scales[i]);
|
| + resolutions.push_back(ash::internal::Resolution(
|
| + gfx::ToFlooredSize(new_size), false /* interlaced */));
|
| + }
|
| + } else {
|
| + for (size_t i = 0; i < display_info.resolutions().size(); ++i)
|
| + resolutions.push_back(display_info.resolutions()[i]);
|
| }
|
| -
|
| - for (size_t i = 0; i < ui_scales.size(); ++i) {
|
| - base::DictionaryValue* scale_info = new base::DictionaryValue();
|
| - scale_info->SetDouble("scale", ui_scales[i]);
|
| - scale_info->SetInteger(
|
| - "width", gfx::ToFlooredInt(base_size.width() * ui_scales[i]));
|
| - scale_info->SetInteger(
|
| - "height", gfx::ToFlooredInt(base_size.height() * ui_scales[i]));
|
| - scale_info->SetBoolean("selected",
|
| - display_info.ui_scale() == ui_scales[i]);
|
| - js_scales->Append(scale_info);
|
| + std::sort(resolutions.begin(), resolutions.end(), CompareResolution);
|
| +
|
| + base::ListValue* js_resolutions = new base::ListValue();
|
| + gfx::Size current_size(bounds.width() * display.device_scale_factor(),
|
| + bounds.height() * display.device_scale_factor());
|
| + for (size_t i = 0; i < resolutions.size(); ++i) {
|
| + base::DictionaryValue* resolution_info = new base::DictionaryValue();
|
| + if (!ui_scales.empty()) {
|
| + resolution_info->SetDouble("scale", ui_scales[i]);
|
| + if (ui_scales[i] == 1.0f)
|
| + resolution_info->SetBoolean("isBest", true);
|
| + resolution_info->SetBoolean(
|
| + "selected", display_info.ui_scale() == ui_scales[i]);
|
| + } else {
|
| + // Picks the largest one as the "best", which is the last element
|
| + // because |resolutions| is sorted by its area.
|
| + if (i == resolutions.size() - 1)
|
| + resolution_info->SetBoolean("isBest", true);
|
| + resolution_info->SetBoolean(
|
| + "selected", (resolutions[i].size == current_size));
|
| + }
|
| + resolution_info->SetInteger("width", resolutions[i].size.width());
|
| + resolution_info->SetInteger("height",resolutions[i].size.height());
|
| + js_resolutions->Append(resolution_info);
|
| }
|
| - js_display->Set("uiScales", js_scales);
|
| + js_display->Set("resolutions", js_resolutions);
|
| js_displays.Append(js_display);
|
| }
|
|
|
| @@ -284,18 +317,35 @@ void DisplayOptionsHandler::HandleSetUIScale(const base::ListValue* args) {
|
| if (display_id == gfx::Display::kInvalidDisplayID)
|
| return;
|
|
|
| - std::string ui_scale_value;
|
| double ui_scale = 0.0f;
|
| - if (!args->GetString(1, &ui_scale_value)) {
|
| - LOG(ERROR) << "Ca't find new ui_scale";
|
| + if (!args->GetDouble(1, &ui_scale) || ui_scale == 0.0f) {
|
| + LOG(ERROR) << "Can't find new ui_scale";
|
| return;
|
| }
|
| - if (!base::StringToDouble(ui_scale_value, &ui_scale)) {
|
| - LOG(ERROR) << "Invalid ui_scale: " << ui_scale_value;
|
| +
|
| + GetDisplayManager()->SetDisplayUIScale(display_id, ui_scale);
|
| +}
|
| +
|
| +void DisplayOptionsHandler::HandleSetResolution(const base::ListValue* args) {
|
| + DCHECK(!args->empty());
|
| + int64 display_id = GetDisplayId(args);
|
| + if (display_id == gfx::Display::kInvalidDisplayID)
|
| + return;
|
| +
|
| + double width = 0.0f;
|
| + double height = 0.0f;
|
| + if (!args->GetDouble(1, &width) || width == 0.0f) {
|
| + LOG(ERROR) << "Can't find new width";
|
| + return;
|
| + }
|
| + if (!args->GetDouble(2, &height) || height == 0.0f) {
|
| + LOG(ERROR) << "Can't find new height";
|
| return;
|
| }
|
|
|
| - GetDisplayManager()->SetDisplayUIScale(display_id, ui_scale);
|
| + // TODO(mukai): creates a confirmation dialog.
|
| + GetDisplayManager()->SetDisplayResolution(
|
| + display_id, gfx::ToFlooredSize(gfx::SizeF(width, height)));
|
| }
|
|
|
| void DisplayOptionsHandler::HandleSetOrientation(const base::ListValue* args) {
|
|
|