| Index: chrome/browser/extensions/display_info_provider_chromeos.cc
|
| diff --git a/chrome/browser/extensions/display_info_provider_chromeos.cc b/chrome/browser/extensions/display_info_provider_chromeos.cc
|
| index 3238b428668a6f70011de89a9151c71d8934101b..1b2dc27ce259a03e96fb4b42ab50f92ff01a8a43 100644
|
| --- a/chrome/browser/extensions/display_info_provider_chromeos.cc
|
| +++ b/chrome/browser/extensions/display_info_provider_chromeos.cc
|
| @@ -16,15 +16,13 @@
|
| #include "extensions/common/api/system_display.h"
|
| #include "ui/display/display.h"
|
| #include "ui/display/manager/display_layout.h"
|
| +#include "ui/display/manager/display_layout_builder.h"
|
| #include "ui/gfx/geometry/point.h"
|
| #include "ui/gfx/geometry/rect.h"
|
|
|
| namespace extensions {
|
|
|
| -using api::system_display::Bounds;
|
| -using api::system_display::DisplayUnitInfo;
|
| -using api::system_display::DisplayProperties;
|
| -using api::system_display::Insets;
|
| +namespace system_display = api::system_display;
|
|
|
| namespace {
|
|
|
| @@ -62,6 +60,41 @@ display::Display::Rotation DegreesToRotation(int degrees) {
|
| }
|
| }
|
|
|
| +// Converts system_display::LayoutPosition to
|
| +// display::DisplayPlacement::Position.
|
| +display::DisplayPlacement::Position GetDisplayPlacementPosition(
|
| + system_display::LayoutPosition position) {
|
| + switch (position) {
|
| + case system_display::LAYOUT_POSITION_TOP:
|
| + return display::DisplayPlacement::TOP;
|
| + case system_display::LAYOUT_POSITION_BOTTOM:
|
| + return display::DisplayPlacement::BOTTOM;
|
| + case system_display::LAYOUT_POSITION_LEFT:
|
| + return display::DisplayPlacement::LEFT;
|
| + case system_display::LAYOUT_POSITION_RIGHT:
|
| + default:
|
| + // Default: layout to the right.
|
| + return display::DisplayPlacement::RIGHT;
|
| + }
|
| +}
|
| +
|
| +// Converts display::DisplayPlacement::Position to
|
| +// system_display::LayoutPosition.
|
| +system_display::LayoutPosition GetLayoutPosition(
|
| + display::DisplayPlacement::Position position) {
|
| + switch (position) {
|
| + case display::DisplayPlacement::TOP:
|
| + return system_display::LayoutPosition::LAYOUT_POSITION_TOP;
|
| + case display::DisplayPlacement::RIGHT:
|
| + return system_display::LayoutPosition::LAYOUT_POSITION_RIGHT;
|
| + case display::DisplayPlacement::BOTTOM:
|
| + return system_display::LayoutPosition::LAYOUT_POSITION_BOTTOM;
|
| + case display::DisplayPlacement::LEFT:
|
| + return system_display::LayoutPosition::LAYOUT_POSITION_LEFT;
|
| + }
|
| + return system_display::LayoutPosition::LAYOUT_POSITION_NONE;
|
| +}
|
| +
|
| // Checks if the given point is over the radius vector described by it's end
|
| // point |vector|. The point is over a vector if it's on its positive (left)
|
| // side. The method sees a point on the same line as the vector as being over
|
| @@ -193,7 +226,7 @@ void UpdateDisplayLayout(const gfx::Rect& primary_display_bounds,
|
| // desired display and the current display manager state.
|
| // Returns whether the parameters are valid. On failure |error| is set to the
|
| // error message.
|
| -bool ValidateParamsForDisplay(const DisplayProperties& info,
|
| +bool ValidateParamsForDisplay(const system_display::DisplayProperties& info,
|
| const display::Display& display,
|
| ash::DisplayManager* display_manager,
|
| int64_t primary_display_id,
|
| @@ -319,11 +352,11 @@ bool ValidateParamsForDisplay(const DisplayProperties& info,
|
| return true;
|
| }
|
|
|
| -extensions::api::system_display::DisplayMode GetDisplayMode(
|
| +system_display::DisplayMode GetDisplayMode(
|
| ash::DisplayManager* display_manager,
|
| const ash::DisplayInfo& display_info,
|
| const ash::DisplayMode& display_mode) {
|
| - extensions::api::system_display::DisplayMode result;
|
| + system_display::DisplayMode result;
|
|
|
| bool is_internal = display::Display::HasInternalDisplay() &&
|
| display::Display::InternalDisplayId() == display_info.id();
|
| @@ -342,15 +375,14 @@ extensions::api::system_display::DisplayMode GetDisplayMode(
|
|
|
| } // namespace
|
|
|
| -DisplayInfoProviderChromeOS::DisplayInfoProviderChromeOS() {
|
| -}
|
| +DisplayInfoProviderChromeOS::DisplayInfoProviderChromeOS() {}
|
|
|
| -DisplayInfoProviderChromeOS::~DisplayInfoProviderChromeOS() {
|
| -}
|
| +DisplayInfoProviderChromeOS::~DisplayInfoProviderChromeOS() {}
|
|
|
| -bool DisplayInfoProviderChromeOS::SetInfo(const std::string& display_id_str,
|
| - const DisplayProperties& info,
|
| - std::string* error) {
|
| +bool DisplayInfoProviderChromeOS::SetInfo(
|
| + const std::string& display_id_str,
|
| + const system_display::DisplayProperties& info,
|
| + std::string* error) {
|
| ash::DisplayManager* display_manager =
|
| ash::Shell::GetInstance()->display_manager();
|
| ash::DisplayConfigurationController* display_configuration_controller =
|
| @@ -367,8 +399,8 @@ bool DisplayInfoProviderChromeOS::SetInfo(const std::string& display_id_str,
|
| const display::Display& primary =
|
| display::Screen::GetScreen()->GetPrimaryDisplay();
|
|
|
| - if (!ValidateParamsForDisplay(
|
| - info, target, display_manager, primary.id(), error)) {
|
| + if (!ValidateParamsForDisplay(info, target, display_manager, primary.id(),
|
| + error)) {
|
| return false;
|
| }
|
|
|
| @@ -387,11 +419,9 @@ bool DisplayInfoProviderChromeOS::SetInfo(const std::string& display_id_str,
|
|
|
| // Process 'overscan' parameter.
|
| if (info.overscan) {
|
| - display_manager->SetOverscanInsets(display_id,
|
| - gfx::Insets(info.overscan->top,
|
| - info.overscan->left,
|
| - info.overscan->bottom,
|
| - info.overscan->right));
|
| + display_manager->SetOverscanInsets(
|
| + display_id, gfx::Insets(info.overscan->top, info.overscan->left,
|
| + info.overscan->bottom, info.overscan->right));
|
| }
|
|
|
| // Process 'rotation' parameter.
|
| @@ -412,16 +442,57 @@ bool DisplayInfoProviderChromeOS::SetInfo(const std::string& display_id_str,
|
| gfx::Rect target_bounds = target.bounds();
|
| target_bounds.Offset(new_bounds_origin.x() - target.bounds().x(),
|
| new_bounds_origin.y() - target.bounds().y());
|
| - UpdateDisplayLayout(
|
| - primary.bounds(), primary.id(), target_bounds, target.id());
|
| + UpdateDisplayLayout(primary.bounds(), primary.id(), target_bounds,
|
| + target.id());
|
| }
|
|
|
| return true;
|
| }
|
|
|
| +bool DisplayInfoProviderChromeOS::SetDisplayLayout(
|
| + const DisplayLayoutList& layouts) {
|
| + ash::DisplayManager* display_manager =
|
| + ash::Shell::GetInstance()->display_manager();
|
| + display::DisplayLayoutBuilder builder(
|
| + display_manager->GetCurrentDisplayLayout());
|
| +
|
| + bool have_root = false;
|
| + builder.ClearPlacements();
|
| + for (const system_display::DisplayLayout& layout : layouts) {
|
| + display::Display display = GetDisplay(layout.id);
|
| + if (display.id() == display::Display::kInvalidDisplayID) {
|
| + LOG(ERROR) << "Invalid layout: display id not found: " << layout.id;
|
| + return false;
|
| + }
|
| + display::Display parent = GetDisplay(layout.parent_id);
|
| + if (parent.id() == display::Display::kInvalidDisplayID) {
|
| + if (have_root) {
|
| + LOG(ERROR) << "Invalid layout: multople roots.";
|
| + return false;
|
| + }
|
| + have_root = true;
|
| + continue; // No placement for root (primary) display.
|
| + }
|
| + display::DisplayPlacement::Position position =
|
| + GetDisplayPlacementPosition(layout.position);
|
| + builder.AddDisplayPlacement(display.id(), parent.id(), position,
|
| + layout.offset);
|
| + }
|
| + std::unique_ptr<display::DisplayLayout> layout = builder.Build();
|
| + if (!display::DisplayLayout::Validate(
|
| + display_manager->GetCurrentDisplayIdList(), *layout)) {
|
| + LOG(ERROR) << "Invalid layout: Validate failed.";
|
| + return false;
|
| + }
|
| + ash::Shell::GetInstance()
|
| + ->display_configuration_controller()
|
| + ->SetDisplayLayout(std::move(layout), true /* user_action */);
|
| + return true;
|
| +}
|
| +
|
| void DisplayInfoProviderChromeOS::UpdateDisplayUnitInfoForPlatform(
|
| const display::Display& display,
|
| - extensions::api::system_display::DisplayUnitInfo* unit) {
|
| + system_display::DisplayUnitInfo* unit) {
|
| ash::DisplayManager* display_manager =
|
| ash::Shell::GetInstance()->display_manager();
|
| unit->name = display_manager->GetDisplayNameForId(display.id());
|
| @@ -456,7 +527,8 @@ void DisplayInfoProviderChromeOS::EnableUnifiedDesktop(bool enable) {
|
| enable);
|
| }
|
|
|
| -DisplayUnitInfoList DisplayInfoProviderChromeOS::GetAllDisplaysInfo() {
|
| +DisplayInfoProvider::DisplayUnitInfoList
|
| +DisplayInfoProviderChromeOS::GetAllDisplaysInfo() {
|
| ash::DisplayManager* display_manager =
|
| ash::Shell::GetInstance()->display_manager();
|
| if (!display_manager->IsInUnifiedMode())
|
| @@ -470,7 +542,7 @@ DisplayUnitInfoList DisplayInfoProviderChromeOS::GetAllDisplaysInfo() {
|
| int64_t primary_id = displays[0].id();
|
| DisplayUnitInfoList all_displays;
|
| for (const display::Display& display : displays) {
|
| - api::system_display::DisplayUnitInfo unit =
|
| + system_display::DisplayUnitInfo unit =
|
| CreateDisplayUnitInfo(display, primary_id);
|
| UpdateDisplayUnitInfoForPlatform(display, &unit);
|
| all_displays.push_back(std::move(unit));
|
| @@ -478,6 +550,31 @@ DisplayUnitInfoList DisplayInfoProviderChromeOS::GetAllDisplaysInfo() {
|
| return all_displays;
|
| }
|
|
|
| +DisplayInfoProvider::DisplayLayoutList
|
| +DisplayInfoProviderChromeOS::GetDisplayLayout() {
|
| + ash::DisplayManager* display_manager =
|
| + ash::Shell::GetInstance()->display_manager();
|
| +
|
| + display::Screen* screen = display::Screen::GetScreen();
|
| + std::vector<display::Display> displays = screen->GetAllDisplays();
|
| +
|
| + DisplayLayoutList result;
|
| + for (const display::Display& display : displays) {
|
| + const display::DisplayPlacement placement =
|
| + display_manager->GetCurrentDisplayLayout().FindPlacementById(
|
| + display.id());
|
| + if (placement.display_id == display::Display::kInvalidDisplayID)
|
| + continue;
|
| + system_display::DisplayLayout display_layout;
|
| + display_layout.id = base::Int64ToString(placement.display_id);
|
| + display_layout.parent_id = base::Int64ToString(placement.parent_display_id);
|
| + display_layout.position = GetLayoutPosition(placement.position);
|
| + display_layout.offset = placement.offset;
|
| + result.push_back(std::move(display_layout));
|
| + }
|
| + return result;
|
| +}
|
| +
|
| bool DisplayInfoProviderChromeOS::OverscanCalibrationStart(
|
| const std::string& id) {
|
| VLOG(1) << "OverscanCalibrationStart: " << id;
|
| @@ -494,7 +591,7 @@ bool DisplayInfoProviderChromeOS::OverscanCalibrationStart(
|
|
|
| bool DisplayInfoProviderChromeOS::OverscanCalibrationAdjust(
|
| const std::string& id,
|
| - const api::system_display::Insets& delta) {
|
| + const system_display::Insets& delta) {
|
| VLOG(1) << "OverscanCalibrationAdjust: " << id;
|
| chromeos::OverscanCalibrator* calibrator = GetCalibrator(id);
|
| if (!calibrator)
|
|
|