Commit 6b6b446d authored by Min Chen's avatar Min Chen Committed by Commit Bot

Parse power button position switch accroding to the updated format.

Bug: 818331
Change-Id: I811f3f12af9c75e9be2581d38e89093deb023c0a
Reviewed-on: https://chromium-review.googlesource.com/1050877
Commit-Queue: Min Chen <minch@chromium.org>
Reviewed-by: default avatarDan Erat <derat@chromium.org>
Reviewed-by: default avatarQiang Xu <warx@google.com>
Cr-Commit-Position: refs/heads/master@{#557246}
parent fbeba958
......@@ -90,13 +90,11 @@ constexpr base::TimeDelta PowerButtonController::kIgnoreRepeatedButtonUpDelay;
constexpr base::TimeDelta
PowerButtonController::kIgnorePowerButtonAfterResumeDelay;
constexpr const char* PowerButtonController::kPositionField;
constexpr const char* PowerButtonController::kXField;
constexpr const char* PowerButtonController::kYField;
constexpr const char* PowerButtonController::kLeftPosition;
constexpr const char* PowerButtonController::kRightPosition;
constexpr const char* PowerButtonController::kTopPosition;
constexpr const char* PowerButtonController::kBottomPosition;
constexpr const char* PowerButtonController::kEdgeField;
constexpr const char* PowerButtonController::kLeftEdge;
constexpr const char* PowerButtonController::kRightEdge;
constexpr const char* PowerButtonController::kTopEdge;
constexpr const char* PowerButtonController::kBottomEdge;
// Maintain active state of the given |widget|. Sets |widget| to always render
// as active if it's not already initially configured that way. Resets the
......@@ -558,42 +556,35 @@ void PowerButtonController::ParsePowerButtonPositionSwitch() {
return;
}
std::string str_power_button_position;
if (!position_info->GetString(kPositionField, &str_power_button_position)) {
LOG(ERROR) << kPositionField << " field is always needed if "
<< switches::kAshPowerButtonPosition << " is set";
std::string edge, position;
if (!position_info->GetString(kEdgeField, &edge) ||
!position_info->GetDouble(kPositionField,
&power_button_offset_percentage_)) {
LOG(ERROR) << "Both " << kEdgeField << " field and " << kPositionField
<< " are always needed if " << switches::kAshPowerButtonPosition
<< " is set";
return;
}
if (str_power_button_position == kLeftPosition) {
if (edge == kLeftEdge) {
power_button_position_ = PowerButtonPosition::LEFT;
} else if (str_power_button_position == kRightPosition) {
} else if (edge == kRightEdge) {
power_button_position_ = PowerButtonPosition::RIGHT;
} else if (str_power_button_position == kTopPosition) {
} else if (edge == kTopEdge) {
power_button_position_ = PowerButtonPosition::TOP;
} else if (str_power_button_position == kBottomPosition) {
} else if (edge == kBottomEdge) {
power_button_position_ = PowerButtonPosition::BOTTOM;
} else {
LOG(ERROR) << "Invalid " << kPositionField << " field in "
LOG(ERROR) << "Invalid " << kEdgeField << " field in "
<< switches::kAshPowerButtonPosition;
return;
}
if (power_button_position_ == PowerButtonPosition::LEFT ||
power_button_position_ == PowerButtonPosition::RIGHT) {
if (!position_info->GetDouble(kYField, &power_button_offset_percentage_)) {
LOG(ERROR) << kYField << " not set in "
<< switches::kAshPowerButtonPosition;
power_button_position_ = PowerButtonPosition::NONE;
return;
}
} else {
if (!position_info->GetDouble(kXField, &power_button_offset_percentage_)) {
LOG(ERROR) << kXField << " not set in "
<< switches::kAshPowerButtonPosition;
power_button_position_ = PowerButtonPosition::NONE;
return;
}
if (power_button_offset_percentage_ < 0 ||
power_button_offset_percentage_ > 1.0f) {
LOG(ERROR) << "Invalid " << kPositionField << " field in "
<< switches::kAshPowerButtonPosition;
power_button_position_ = PowerButtonPosition::NONE;
}
}
......
......@@ -78,15 +78,14 @@ class ASH_EXPORT PowerButtonController
// Value of switches::kAshPowerButtonPosition stored in JSON format. These
// are the field names of the flag.
static constexpr const char* kEdgeField = "edge";
static constexpr const char* kPositionField = "position";
static constexpr const char* kXField = "x";
static constexpr const char* kYField = "y";
// Value of |kPositionField|.
static constexpr const char* kLeftPosition = "left";
static constexpr const char* kRightPosition = "right";
static constexpr const char* kTopPosition = "top";
static constexpr const char* kBottomPosition = "bottom";
// Value of |kEdgeField|.
static constexpr const char* kLeftEdge = "left";
static constexpr const char* kRightEdge = "right";
static constexpr const char* kTopEdge = "top";
static constexpr const char* kBottomEdge = "bottom";
explicit PowerButtonController(
BacklightsForcedOffSetter* backlights_forced_off_setter);
......
......@@ -1024,31 +1024,26 @@ class PowerButtonControllerWithPositionTest
base::DictionaryValue position_info;
switch (power_button_position_) {
case PowerButtonPosition::LEFT:
position_info.SetString(PowerButtonController::kPositionField,
PowerButtonController::kLeftPosition);
position_info.SetString(PowerButtonController::kEdgeField,
PowerButtonController::kLeftEdge);
break;
case PowerButtonPosition::RIGHT:
position_info.SetString(PowerButtonController::kPositionField,
PowerButtonController::kRightPosition);
position_info.SetString(PowerButtonController::kEdgeField,
PowerButtonController::kRightEdge);
break;
case PowerButtonPosition::TOP:
position_info.SetString(PowerButtonController::kPositionField,
PowerButtonController::kTopPosition);
position_info.SetString(PowerButtonController::kEdgeField,
PowerButtonController::kTopEdge);
break;
case PowerButtonPosition::BOTTOM:
position_info.SetString(PowerButtonController::kPositionField,
PowerButtonController::kBottomPosition);
position_info.SetString(PowerButtonController::kEdgeField,
PowerButtonController::kBottomEdge);
break;
default:
return;
}
if (IsLeftOrRightPosition()) {
position_info.SetDouble(PowerButtonController::kYField,
kPowerButtonPercentage);
} else {
position_info.SetDouble(PowerButtonController::kXField,
kPowerButtonPercentage);
}
position_info.SetDouble(PowerButtonController::kPositionField,
kPowerButtonPercentage);
std::string json_position_info;
base::JSONWriter::Write(position_info, &json_position_info);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment