Commit bb76e2f3 authored by Tatsuhisa Yamaguchi's avatar Tatsuhisa Yamaguchi Committed by Commit Bot

Add tooltip for battery icon in the system tray.

Bug: 888072
Change-Id: Ifaa3ccecf4d21ae23054523290b2b87b033688f5
Reviewed-on: https://chromium-review.googlesource.com/c/1306969Reviewed-by: default avatarTetsui Ohkubo <tetsui@chromium.org>
Commit-Queue: Tatsuhisa Yamaguchi <yamaguchi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604173}
parent f58bce86
......@@ -451,6 +451,23 @@ std::pair<base::string16, base::string16> PowerStatus::GetStatusStrings()
return std::make_pair(percentage, status);
}
base::string16 PowerStatus::GetInlinedStatusString() const {
base::string16 percentage_text;
base::string16 status_text;
std::tie(percentage_text, status_text) = GetStatusStrings();
if (!percentage_text.empty() && !status_text.empty()) {
return percentage_text +
l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_BATTERY_STATUS_SEPARATOR) +
status_text;
} else if (!percentage_text.empty()) {
return percentage_text;
} else {
return status_text;
}
}
PowerStatus::PowerStatus() {
chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(
this);
......
......@@ -197,6 +197,10 @@ class ASH_EXPORT PowerStatus : public chromeos::PowerManagerClient::Observer {
// empty string.
std::pair<base::string16, base::string16> GetStatusStrings() const;
// Returns status strings that are generated by current PowerStatus.
// For example, "53% - 5:00 left".
base::string16 GetInlinedStatusString() const;
// Updates |proto_|. Does not notify observers.
void SetProtoForTesting(const power_manager::PowerSupplyProperties& proto);
......
......@@ -57,6 +57,18 @@ void PowerTrayView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
node_data->role = ax::mojom::Role::kButton;
}
views::View* PowerTrayView::GetTooltipHandlerForPoint(const gfx::Point& point) {
return this;
}
bool PowerTrayView::GetTooltipText(const gfx::Point& p,
base::string16* tooltip) const {
if (tooltip_.empty())
return false;
*tooltip = tooltip_;
return true;
}
void PowerTrayView::OnPowerStatusChanged() {
UpdateStatus();
}
......@@ -69,6 +81,10 @@ void PowerTrayView::UpdateStatus() {
UpdateImage();
SetVisible(PowerStatus::Get()->IsBatteryPresent());
accessible_name_ = PowerStatus::Get()->GetAccessibleNameString(true);
tooltip_ = PowerStatus::Get()->GetInlinedStatusString();
// Currently ChromeVox only reads the inner view when touching the icon.
// As a result this node's accessible node data will not be read.
image_view()->SetAccessibleName(accessible_name_);
}
void PowerTrayView::UpdateImage() {
......
......@@ -27,6 +27,9 @@ class PowerTrayView : public TrayItemView,
// views::View:
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
views::View* GetTooltipHandlerForPoint(const gfx::Point& point) override;
bool GetTooltipText(const gfx::Point& p,
base::string16* tooltip) const override;
// PowerStatus::Observer:
void OnPowerStatusChanged() override;
......@@ -39,6 +42,7 @@ class PowerTrayView : public TrayItemView,
void UpdateImage();
base::string16 accessible_name_;
base::string16 tooltip_;
base::Optional<PowerStatus::BatteryImageInfo> info_;
session_manager::SessionState icon_session_state_color_ =
session_manager::SessionState::UNKNOWN;
......
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