OLD | NEW |
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 "chrome/browser/ui/webui/options/chromeos/display_options_handler.h" | 5 #include "chrome/browser/ui/webui/options/chromeos/display_options_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "ash/display/display_controller.h" | 9 #include "ash/display/display_controller.h" |
10 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
11 #include "ash/display/output_configurator_animation.h" | 11 #include "ash/display/output_configurator_animation.h" |
| 12 #include "ash/display/resolution_notification_controller.h" |
12 #include "ash/screen_ash.h" | 13 #include "ash/screen_ash.h" |
13 #include "ash/shell.h" | 14 #include "ash/shell.h" |
14 #include "base/bind.h" | 15 #include "base/bind.h" |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
16 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
17 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
18 #include "base/values.h" | 19 #include "base/values.h" |
19 #include "chrome/browser/chromeos/display/display_preferences.h" | 20 #include "chrome/browser/chromeos/display/display_preferences.h" |
20 #include "chromeos/display/output_configurator.h" | 21 #include "chromeos/display/output_configurator.h" |
21 #include "content/public/browser/web_ui.h" | 22 #include "content/public/browser/web_ui.h" |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 double height = 0.0f; | 338 double height = 0.0f; |
338 if (!args->GetDouble(1, &width) || width == 0.0f) { | 339 if (!args->GetDouble(1, &width) || width == 0.0f) { |
339 LOG(ERROR) << "Can't find new width"; | 340 LOG(ERROR) << "Can't find new width"; |
340 return; | 341 return; |
341 } | 342 } |
342 if (!args->GetDouble(2, &height) || height == 0.0f) { | 343 if (!args->GetDouble(2, &height) || height == 0.0f) { |
343 LOG(ERROR) << "Can't find new height"; | 344 LOG(ERROR) << "Can't find new height"; |
344 return; | 345 return; |
345 } | 346 } |
346 | 347 |
347 // TODO(mukai): creates a confirmation dialog. | 348 const ash::internal::DisplayInfo& display_info = |
348 GetDisplayManager()->SetDisplayResolution( | 349 GetDisplayManager()->GetDisplayInfo(display_id); |
349 display_id, gfx::ToFlooredSize(gfx::SizeF(width, height))); | 350 gfx::Size new_resolution = gfx::ToFlooredSize(gfx::SizeF(width, height)); |
| 351 gfx::Size old_resolution = display_info.size_in_pixel(); |
| 352 bool has_new_resolution = false; |
| 353 bool has_old_resolution = false; |
| 354 for (size_t i = 0; i < display_info.resolutions().size(); ++i) { |
| 355 ash::internal::Resolution resolution = display_info.resolutions()[i]; |
| 356 if (resolution.size == new_resolution) |
| 357 has_new_resolution = true; |
| 358 if (resolution.size == old_resolution) |
| 359 has_old_resolution = true; |
| 360 } |
| 361 if (!has_new_resolution) { |
| 362 LOG(ERROR) << "No new resolution " << new_resolution.ToString() |
| 363 << " is found in the display info " << display_info.ToString(); |
| 364 return; |
| 365 } |
| 366 if (!has_old_resolution) { |
| 367 LOG(ERROR) << "No old resolution " << old_resolution.ToString() |
| 368 << " is found in the display info " << display_info.ToString(); |
| 369 return; |
| 370 } |
| 371 |
| 372 ash::Shell::GetInstance()->resolution_notification_controller()-> |
| 373 SetDisplayResolutionAndNotify( |
| 374 display_id, old_resolution, new_resolution, |
| 375 base::Bind(&StoreDisplayPrefs)); |
350 } | 376 } |
351 | 377 |
352 void DisplayOptionsHandler::HandleSetOrientation(const base::ListValue* args) { | 378 void DisplayOptionsHandler::HandleSetOrientation(const base::ListValue* args) { |
353 DCHECK(!args->empty()); | 379 DCHECK(!args->empty()); |
354 | 380 |
355 int64 display_id = GetDisplayId(args); | 381 int64 display_id = GetDisplayId(args); |
356 if (display_id == gfx::Display::kInvalidDisplayID) | 382 if (display_id == gfx::Display::kInvalidDisplayID) |
357 return; | 383 return; |
358 | 384 |
359 std::string rotation_value; | 385 std::string rotation_value; |
360 gfx::Display::Rotation new_rotation = gfx::Display::ROTATE_0; | 386 gfx::Display::Rotation new_rotation = gfx::Display::ROTATE_0; |
361 if (!args->GetString(1, &rotation_value)) { | 387 if (!args->GetString(1, &rotation_value)) { |
362 LOG(ERROR) << "Can't find new orientation"; | 388 LOG(ERROR) << "Can't find new orientation"; |
363 return; | 389 return; |
364 } | 390 } |
365 if (rotation_value == "90") | 391 if (rotation_value == "90") |
366 new_rotation = gfx::Display::ROTATE_90; | 392 new_rotation = gfx::Display::ROTATE_90; |
367 else if (rotation_value == "180") | 393 else if (rotation_value == "180") |
368 new_rotation = gfx::Display::ROTATE_180; | 394 new_rotation = gfx::Display::ROTATE_180; |
369 else if (rotation_value == "270") | 395 else if (rotation_value == "270") |
370 new_rotation = gfx::Display::ROTATE_270; | 396 new_rotation = gfx::Display::ROTATE_270; |
371 else if (rotation_value != "0") | 397 else if (rotation_value != "0") |
372 LOG(ERROR) << "Invalid rotation: " << rotation_value << " Falls back to 0"; | 398 LOG(ERROR) << "Invalid rotation: " << rotation_value << " Falls back to 0"; |
373 | 399 |
374 GetDisplayManager()->SetDisplayRotation(display_id, new_rotation); | 400 GetDisplayManager()->SetDisplayRotation(display_id, new_rotation); |
375 } | 401 } |
376 | 402 |
377 } // namespace options | 403 } // namespace options |
378 } // namespace chromeos | 404 } // namespace chromeos |
OLD | NEW |