Commit 8e58c96f authored by Tim Song's avatar Tim Song Committed by Commit Bot

Ash Tray: Update privacy screen UI to support enterprise managed state.

BUG=1040648

Change-Id: I889021d0515c1246f3dce3ca8c69f5964f8a04e1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2079673Reviewed-by: default avatarAhmed Mehfooz <amehfooz@chromium.org>
Commit-Queue: Tim Song <tengs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#745672}
parent 76e7d8f8
......@@ -1466,14 +1466,20 @@ This file contains the strings for ash.
<message name="IDS_ASH_STATUS_TRAY_PRIVACY_SCREEN_ON_SUBLABEL" desc="The sublabel text under the privacy screen menu button when the feature is toggled on.">
On
</message>
<message name="IDS_ASH_STATUS_TRAY_PRIVACY_SCREEN_MANAGED_SUBLABEL" desc="The sublabel text under the privacy screen menu button when the feature is managed by enterprise policy.">
Managed
</message>
<message name="IDS_ASH_STATUS_TRAY_PRIVACY_SCREEN_TOOLTIP" desc="The tooltip text for the privacy screen menu button.">
Toggle privacy screen. <ph name="STATE_TEXT">$1<ex>Privacy screen is on.</ex></ph>
Toggle privacy screen. <ph name="STATE_TEXT">$1<ex>Privacy screen is on</ex></ph>.
</message>
<message name="IDS_ASH_STATUS_TRAY_PRIVACY_SCREEN_ON_STATE" desc="The text for the button indicating the feature is on.">
Privacy screen is on
</message>
<message name="IDS_ASH_STATUS_TRAY_PRIVACY_SCREEN_TOOLTIP_ON_STATE" desc="The tooltip text for the privacy screen menu button indicating the feature is on.">
Privacy screen is on.
<message name="IDS_ASH_STATUS_TRAY_PRIVACY_SCREEN_OFF_STATE" desc="The text for the privacy screen indicating the feature is off.">
Privacy screen is off
</message>
<message name="IDS_ASH_STATUS_TRAY_PRIVACY_SCREEN_TOOLTIP_OFF_STATE" desc="The tooltip text for the privacy screen menu button indicating the feature is off.">
Privacy screen is off.
<message name="IDS_ASH_STATUS_TRAY_PRIVACY_SCREEN_ENTERPRISE_MANAGED" desc="The text for the privacy screen indicating the feature is enforced by enterprise policy.">
Enforced by your administrator
</message>
<!-- Status tray networking strings. -->
......
......@@ -58,7 +58,9 @@ void PrivacyScreenFeaturePodController::UpdateButton() {
if (!is_supported)
return;
// TODO(tengs): Hook up managed state once it is implemented.
bool is_enabled = privacy_screen_controller->GetEnabled();
bool is_managed = false;
button_->SetVectorIcon(kPrivacyScreenIcon);
button_->SetToggled(is_enabled);
......@@ -69,13 +71,18 @@ void PrivacyScreenFeaturePodController::UpdateButton() {
if (is_enabled) {
button_->SetSubLabel(l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_PRIVACY_SCREEN_ON_SUBLABEL));
tooltip_state = l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_PRIVACY_SCREEN_TOOLTIP_ON_STATE);
tooltip_state =
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_PRIVACY_SCREEN_ON_STATE);
} else {
button_->SetSubLabel(l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_PRIVACY_SCREEN_OFF_SUBLABEL));
tooltip_state = l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_PRIVACY_SCREEN_TOOLTIP_OFF_STATE);
tooltip_state =
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_PRIVACY_SCREEN_OFF_STATE);
}
if (is_managed) {
button_->SetSubLabel(l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_PRIVACY_SCREEN_MANAGED_SUBLABEL));
}
button_->SetIconAndLabelTooltips(l10n_util::GetStringFUTF16(
......
......@@ -39,8 +39,8 @@ void PrivacyScreenToastController::ShowToast() {
TrayBubbleView::InitParams init_params;
init_params.shelf_alignment = tray_->shelf()->alignment();
init_params.min_width = kPrivacyScreenToastWidth;
init_params.max_width = kPrivacyScreenToastWidth;
init_params.min_width = kPrivacyScreenToastMinWidth;
init_params.max_width = kPrivacyScreenToastMaxWidth;
init_params.delegate = this;
init_params.parent_window = tray_->GetBubbleWindowContainer();
init_params.anchor_view = nullptr;
......@@ -107,8 +107,12 @@ void PrivacyScreenToastController::StartAutoCloseTimer() {
void PrivacyScreenToastController::UpdateToastView() {
if (toast_view_) {
// TODO(tengs): Hook up managed state after it is implemented.
auto* privacy_screen_controller = Shell::Get()->privacy_screen_controller();
toast_view_->SetPrivacyScreenEnabled(
Shell::Get()->privacy_screen_controller()->GetEnabled());
/*enabled=*/privacy_screen_controller->GetEnabled(),
/*managed=*/true);
bubble_view_->SetWidth(toast_view_->GetPreferredSize().width());
}
}
......
......@@ -11,12 +11,66 @@
#include "ash/system/tray/tray_constants.h"
#include "ash/system/unified/feature_pod_button.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"
namespace ash {
namespace {
void ConfigureLabel(views::Label* label, SkColor color, int font_size) {
label->SetAutoColorReadabilityEnabled(false);
label->SetSubpixelRenderingEnabled(false);
label->SetEnabledColor(color);
gfx::Font default_font;
gfx::Font label_font =
default_font.Derive(font_size - default_font.GetFontSize(),
gfx::Font::NORMAL, gfx::Font::Weight::NORMAL);
gfx::FontList font_list(label_font);
label->SetFontList(font_list);
}
} // namespace
// View shown if the privacy screen setting is enterprise managed.
class PrivacyScreenToastManagedView : public views::View {
public:
PrivacyScreenToastManagedView() {
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal, gfx::Insets(),
kUnifiedManagedDeviceSpacing));
views::Label* label = new views::Label();
views::ImageView* icon = new views::ImageView();
const AshColorProvider* color_provider = AshColorProvider::Get();
const SkColor label_color = color_provider->GetContentLayerColor(
AshColorProvider::ContentLayerType::kTextSecondary,
AshColorProvider::AshColorMode::kDark);
ConfigureLabel(label, label_color, kPrivacyScreenToastSubLabelFontSize);
label->SetText(l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_PRIVACY_SCREEN_ENTERPRISE_MANAGED));
icon->SetPreferredSize(
gfx::Size(kUnifiedSystemInfoHeight, kUnifiedSystemInfoHeight));
const SkColor icon_color = color_provider->GetContentLayerColor(
AshColorProvider::ContentLayerType::kTextSecondary,
AshColorProvider::AshColorMode::kDark);
icon->SetImage(gfx::CreateVectorIcon(kSystemTrayManagedIcon, icon_color));
AddChildView(label);
AddChildView(icon);
}
~PrivacyScreenToastManagedView() override = default;
};
// View containing the various labels in the toast.
class PrivacyScreenToastLabelView : public views::View {
public:
......@@ -26,54 +80,37 @@ class PrivacyScreenToastLabelView : public views::View {
layout->set_cross_axis_alignment(
views::BoxLayout::CrossAxisAlignment::kStart);
main_label_ = new views::Label();
sub_label_ = new views::Label();
AddChildView(main_label_);
AddChildView(sub_label_);
label_ = new views::Label();
managed_view_ = new PrivacyScreenToastManagedView();
AddChildView(label_);
AddChildView(managed_view_);
const AshColorProvider* color_provider = AshColorProvider::Get();
const SkColor primary_text_color = color_provider->GetContentLayerColor(
AshColorProvider::ContentLayerType::kTextPrimary,
AshColorProvider::AshColorMode::kDark);
const SkColor secondary_text_color = color_provider->GetContentLayerColor(
AshColorProvider::ContentLayerType::kTextSecondary,
AshColorProvider::AshColorMode::kDark);
ConfigureLabel(main_label_, primary_text_color,
ConfigureLabel(label_, primary_text_color,
kPrivacyScreenToastMainLabelFontSize);
ConfigureLabel(sub_label_, secondary_text_color,
kPrivacyScreenToastSubLabelFontSize);
main_label_->SetText(
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_PRIVACY_SCREEN_LABEL));
}
void SetPrivacyScreenEnabled(bool enabled) {
~PrivacyScreenToastLabelView() override = default;
void SetPrivacyScreenEnabled(bool enabled, bool managed) {
if (enabled) {
sub_label_->SetText(l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_PRIVACY_SCREEN_ON_SUBLABEL));
label_->SetText(l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_PRIVACY_SCREEN_ON_STATE));
} else {
sub_label_->SetText(l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_PRIVACY_SCREEN_OFF_SUBLABEL));
label_->SetText(l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_PRIVACY_SCREEN_OFF_STATE));
}
}
private:
void ConfigureLabel(views::Label* label, SkColor color, int font_size) {
label->SetAutoColorReadabilityEnabled(false);
label->SetSubpixelRenderingEnabled(false);
label->SetEnabledColor(color);
gfx::Font default_font;
gfx::Font label_font =
default_font.Derive(font_size - default_font.GetFontSize(),
gfx::Font::NORMAL, gfx::Font::Weight::NORMAL);
gfx::FontList font_list(label_font);
label->SetFontList(font_list);
managed_view_->SetVisible(managed);
}
views::Label* main_label_;
views::Label* sub_label_;
private:
views::Label* label_;
PrivacyScreenToastManagedView* managed_view_;
};
PrivacyScreenToastView::PrivacyScreenToastView(
......@@ -98,14 +135,11 @@ PrivacyScreenToastView::PrivacyScreenToastView(
PrivacyScreenToastView::~PrivacyScreenToastView() = default;
void PrivacyScreenToastView::SetPrivacyScreenEnabled(bool enabled) {
void PrivacyScreenToastView::SetPrivacyScreenEnabled(bool enabled,
bool managed) {
button_->SetToggled(enabled);
label_->SetPrivacyScreenEnabled(enabled);
label_->SetPrivacyScreenEnabled(enabled, managed);
Layout();
}
gfx::Size PrivacyScreenToastView::CalculatePreferredSize() const {
return gfx::Size(kPrivacyScreenToastWidth, kPrivacyScreenToastHeight);
}
} // namespace ash
......@@ -22,13 +22,10 @@ class ASH_EXPORT PrivacyScreenToastView : public views::View {
PrivacyScreenToastView(PrivacyScreenToastView&) = delete;
PrivacyScreenToastView operator=(PrivacyScreenToastView&) = delete;
// Updates the toast with whether the privacy screen is enabled.
void SetPrivacyScreenEnabled(bool enabled);
// Updates the toast with whether the privacy screen is enabled and managed.
void SetPrivacyScreenEnabled(bool enabled, bool managed);
private:
// views::View:
gfx::Size CalculatePreferredSize() const override;
FeaturePodIconButton* button_ = nullptr;
PrivacyScreenToastLabelView* label_ = nullptr;
};
......
......@@ -207,7 +207,8 @@ constexpr int kTrayBubbleInsetTabletModeCompensation = 8;
constexpr int kTrayBubbleInsetHotseatCompensation = 16;
// Constants used for the privacy screen toast.
constexpr int kPrivacyScreenToastWidth = 256;
constexpr int kPrivacyScreenToastMinWidth = 256;
constexpr int kPrivacyScreenToastMaxWidth = 512;
constexpr int kPrivacyScreenToastHeight = 64;
constexpr int kPrivacyScreenToastMainLabelFontSize = 14;
constexpr int kPrivacyScreenToastSubLabelFontSize = 13;
......
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