| Index: ash/display/display_layout.cc
|
| diff --git a/ash/display/display_layout.cc b/ash/display/display_layout.cc
|
| index 23a0eebcb03f2f5158e77635d27a7cd33fe2b78a..1897d76d94a6270e6b506fb45158dd50badf1416 100644
|
| --- a/ash/display/display_layout.cc
|
| +++ b/ash/display/display_layout.cc
|
| @@ -10,10 +10,8 @@
|
| #include "ash/ash_switches.h"
|
| #include "ash/display/display_pref_util.h"
|
| #include "ash/shell.h"
|
| -#include "base/json/json_value_converter.h"
|
| #include "base/logging.h"
|
| #include "base/strings/string_number_conversions.h"
|
| -#include "base/strings/string_piece.h"
|
| #include "base/strings/stringprintf.h"
|
| #include "base/values.h"
|
| #include "ui/gfx/display.h"
|
| @@ -21,50 +19,17 @@
|
| namespace ash {
|
| namespace {
|
|
|
| +// DisplayPlacement Positions
|
| +const char kTop[] = "top";
|
| +const char kRight[] = "right";
|
| +const char kBottom[] = "bottom";
|
| +const char kLeft[] = "left";
|
| +const char kUnknown[] = "unknown";
|
| +
|
| // The maximum value for 'offset' in DisplayLayout in case of outliers. Need
|
| // to change this value in case to support even larger displays.
|
| const int kMaxValidOffset = 10000;
|
|
|
| -// Persistent key names
|
| -const char kMirroredKey[] = "mirrored";
|
| -const char kDefaultUnifiedKey[] = "default_unified";
|
| -const char kPrimaryIdKey[] = "primary-id";
|
| -const char kDisplayPlacementKey[] = "display_placement";
|
| -
|
| -// DisplayPlacement
|
| -const char kPositionKey[] = "position";
|
| -const char kOffsetKey[] = "offset";
|
| -const char kDisplayPlacementDisplayIdKey[] = "display_id";
|
| -const char kDisplayPlacementParentDisplayIdKey[] = "parent_display_id";
|
| -
|
| -using PositionToStringMap = std::map<DisplayPlacement::Position, std::string>;
|
| -using DisplayPlacementMap = std::unordered_map<int64_t, DisplayPlacement>;
|
| -
|
| -const PositionToStringMap* GetPositionToStringMap() {
|
| - static const PositionToStringMap* map = CreateToStringMap(
|
| - DisplayPlacement::TOP, "top", DisplayPlacement::BOTTOM, "bottom",
|
| - DisplayPlacement::RIGHT, "right", DisplayPlacement::LEFT, "left");
|
| - return map;
|
| -}
|
| -
|
| -std::string ToPositionString(DisplayPlacement::Position position) {
|
| - const PositionToStringMap* map = GetPositionToStringMap();
|
| - PositionToStringMap::const_iterator iter = map->find(position);
|
| - return iter != map->end() ? iter->second : std::string("unknown");
|
| -}
|
| -
|
| -bool GetPositionFromString(const base::StringPiece& position,
|
| - DisplayPlacement::Position* field) {
|
| - if (ReverseFind(GetPositionToStringMap(), position, field))
|
| - return true;
|
| - LOG(ERROR) << "Invalid position value:" << position;
|
| - return false;
|
| -}
|
| -
|
| -bool GetDisplayIdFromString(const base::StringPiece& position, int64_t* field) {
|
| - return base::StringToInt64(position, field);
|
| -}
|
| -
|
| bool IsIdInList(int64_t id, const DisplayIdList& list) {
|
| const auto iter =
|
| std::find_if(list.begin(), list.end(),
|
| @@ -130,101 +95,64 @@ std::string DisplayPlacement::ToString() const {
|
| s << "id=" << display_id << ", ";
|
| if (parent_display_id != gfx::Display::kInvalidDisplayID)
|
| s << "parent=" << parent_display_id << ", ";
|
| - s << ToPositionString(position) << ", ";
|
| + s << PositionToString(position) << ", ";
|
| s << offset;
|
| return s.str();
|
| }
|
|
|
| // static
|
| -void DisplayPlacement::RegisterJSONConverter(
|
| - base::JSONValueConverter<DisplayPlacement>* converter) {
|
| - converter->RegisterIntField(kOffsetKey, &DisplayPlacement::offset);
|
| - converter->RegisterCustomField<DisplayPlacement::Position>(
|
| - kPositionKey, &DisplayPlacement::position, &GetPositionFromString);
|
| - converter->RegisterCustomField<int64_t>(kDisplayPlacementDisplayIdKey,
|
| - &DisplayPlacement::display_id,
|
| - &GetDisplayIdFromString);
|
| - converter->RegisterCustomField<int64_t>(kDisplayPlacementParentDisplayIdKey,
|
| - &DisplayPlacement::parent_display_id,
|
| - &GetDisplayIdFromString);
|
| +std::string DisplayPlacement::PositionToString(Position position) {
|
| + switch (position) {
|
| + case TOP:
|
| + return kTop;
|
| + case RIGHT:
|
| + return kRight;
|
| + case BOTTOM:
|
| + return kBottom;
|
| + case LEFT:
|
| + return kLeft;
|
| + }
|
| + return kUnknown;
|
| }
|
|
|
| -////////////////////////////////////////////////////////////////////////////////
|
| -// DisplayLayout
|
| -
|
| -DisplayLayout::DisplayLayout()
|
| - : mirrored(false),
|
| - default_unified(true),
|
| - primary_id(gfx::Display::kInvalidDisplayID) {}
|
| -
|
| -DisplayLayout::~DisplayLayout() {}
|
| -
|
| // static
|
| -bool DisplayLayout::ConvertFromValue(const base::Value& value,
|
| - DisplayLayout* layout) {
|
| - layout->placement_list.clear();
|
| - base::JSONValueConverter<DisplayLayout> converter;
|
| - if (!converter.Convert(value, layout))
|
| - return false;
|
| - if (layout->placement_list.size() != 0u)
|
| +bool DisplayPlacement::StringToPosition(const base::StringPiece& string,
|
| + Position* position) {
|
| + if (string == kTop) {
|
| + *position = TOP;
|
| return true;
|
| - // For compatibility with old format.
|
| - const base::DictionaryValue* dict_value = nullptr;
|
| - if (!value.GetAsDictionary(&dict_value) || dict_value == nullptr)
|
| - return false;
|
| - int offset;
|
| - if (dict_value->GetInteger(kOffsetKey, &offset)) {
|
| - DisplayPlacement::Position position;
|
| - std::string position_str;
|
| - if (!dict_value->GetString(kPositionKey, &position_str))
|
| - return false;
|
| - GetPositionFromString(position_str, &position);
|
| - layout->placement_list.push_back(new DisplayPlacement(position, offset));
|
| }
|
| - return true;
|
| -}
|
|
|
| -// static
|
| -bool DisplayLayout::ConvertToValue(const DisplayLayout& layout,
|
| - base::Value* value) {
|
| - base::DictionaryValue* dict_value = nullptr;
|
| - if (!value->GetAsDictionary(&dict_value) || dict_value == nullptr)
|
| - return false;
|
| + if (string == kRight) {
|
| + *position = RIGHT;
|
| + return true;
|
| + }
|
|
|
| - dict_value->SetBoolean(kMirroredKey, layout.mirrored);
|
| - dict_value->SetBoolean(kDefaultUnifiedKey, layout.default_unified);
|
| - dict_value->SetString(kPrimaryIdKey, base::Int64ToString(layout.primary_id));
|
| + if (string == kBottom) {
|
| + *position = BOTTOM;
|
| + return true;
|
| + }
|
|
|
| - scoped_ptr<base::ListValue> placement_list(new base::ListValue);
|
| - for (const auto* placement : layout.placement_list) {
|
| - scoped_ptr<base::DictionaryValue> placement_value(
|
| - new base::DictionaryValue);
|
| - placement_value->SetString(kPositionKey,
|
| - ToPositionString(placement->position));
|
| - placement_value->SetInteger(kOffsetKey, placement->offset);
|
| - placement_value->SetString(kDisplayPlacementDisplayIdKey,
|
| - base::Int64ToString(placement->display_id));
|
| - placement_value->SetString(
|
| - kDisplayPlacementParentDisplayIdKey,
|
| - base::Int64ToString(placement->parent_display_id));
|
| - placement_list->Append(std::move(placement_value));
|
| + if (string == kLeft) {
|
| + *position = LEFT;
|
| + return true;
|
| }
|
| - dict_value->Set(kDisplayPlacementKey, std::move(placement_list));
|
| - return true;
|
| -}
|
|
|
| -// static
|
| -void DisplayLayout::RegisterJSONConverter(
|
| - base::JSONValueConverter<DisplayLayout>* converter) {
|
| - converter->RegisterBoolField(kMirroredKey, &DisplayLayout::mirrored);
|
| - converter->RegisterBoolField(kDefaultUnifiedKey,
|
| - &DisplayLayout::default_unified);
|
| - converter->RegisterCustomField<int64_t>(
|
| - kPrimaryIdKey, &DisplayLayout::primary_id, &GetDisplayIdFromString);
|
| - converter->RegisterRepeatedMessage<DisplayPlacement>(
|
| - kDisplayPlacementKey, &DisplayLayout::placement_list);
|
| + LOG(ERROR) << "Invalid position value:" << string;
|
| +
|
| + return false;
|
| }
|
|
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// DisplayLayout
|
| +
|
| +DisplayLayout::DisplayLayout()
|
| + : mirrored(false),
|
| + default_unified(true),
|
| + primary_id(gfx::Display::kInvalidDisplayID) {}
|
| +
|
| +DisplayLayout::~DisplayLayout() {}
|
| +
|
| // static
|
| bool DisplayLayout::Validate(const DisplayIdList& list,
|
| const DisplayLayout& layout) {
|
|
|