Skip to content

Commit

Permalink
Add device management disclosure on login/lock screen
Browse files Browse the repository at this point in the history
Bug: 1015746
Change-Id: Iacb82292baccbbbc95c32cf1dd86a1859bd1336d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2096957
Reviewed-by: Denis Kuznetsov [CET] <antrim@chromium.org>
Reviewed-by: Roman Sorokin [CET] <rsorokin@chromium.org>
Commit-Queue: Thomas Tellier <tellier@google.com>
Cr-Commit-Position: refs/heads/master@{#785735}
  • Loading branch information
Thomas Tellier authored and Commit Bot committed Jul 7, 2020
1 parent e501689 commit 194c4ac
Show file tree
Hide file tree
Showing 9 changed files with 242 additions and 62 deletions.
41 changes: 22 additions & 19 deletions ash/login/ui/bottom_status_indicator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,48 @@
// found in the LICENSE file.
#include "ash/login/ui/bottom_status_indicator.h"

#include "ui/accessibility/ax_enums.mojom.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "base/strings/string16.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"

namespace ash {

BottomStatusIndicator::BottomStatusIndicator() {
icon_ = new views::ImageView;
AddChildView(icon_);

label_ = new views::Label();
label_->SetAutoColorReadabilityEnabled(false);
label_->SetFontList(
BottomStatusIndicator::BottomStatusIndicator(TappedCallback on_tapped_callback)
: LabelButton(this, base::string16()),
on_tapped_callback_(std::move(on_tapped_callback)) {
label()->SetAutoColorReadabilityEnabled(false);
label()->SetFontList(
views::Label::GetDefaultFontList().DeriveWithSizeDelta(1));
label_->SetSubpixelRenderingEnabled(false);
AddChildView(label_);
label()->SetSubpixelRenderingEnabled(false);

SetFocusBehavior(FocusBehavior::ALWAYS);

SetVisible(false);
}

void BottomStatusIndicator::SetText(const base::string16& text, SkColor color) {
label_->SetText(text);
label_->SetEnabledColor(color);
}
BottomStatusIndicator::~BottomStatusIndicator() = default;

void BottomStatusIndicator::SetIcon(const gfx::VectorIcon& vector_icon,
AshColorProvider::ContentLayerType type) {
icon_->SetImage(gfx::CreateVectorIcon(
vector_icon, AshColorProvider::Get()->GetContentLayerColor(
type, AshColorProvider::AshColorMode::kDark)));
SetImage(views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(
vector_icon, AshColorProvider::Get()->GetContentLayerColor(
type, AshColorProvider::AshColorMode::kDark)));
}

void BottomStatusIndicator::ButtonPressed(views::Button* sender,
const ui::Event& event) {
DCHECK(sender == this);
DCHECK(on_tapped_callback_);
on_tapped_callback_.Run();
}

void BottomStatusIndicator::GetAccessibleNodeData(ui::AXNodeData* node_data) {
node_data->role = ax::mojom::Role::kTooltip;
node_data->SetName(label_->GetText());
node_data->role = role_;
node_data->SetName(label()->GetText());
}

} // namespace ash
36 changes: 13 additions & 23 deletions ash/login/ui/bottom_status_indicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,40 @@

#include "ash/style/ash_color_provider.h"
#include "base/strings/string16.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/view.h"

namespace gfx {
struct VectorIcon;
}

namespace views {
class ImageView;
class Label;
} // namespace views

namespace ash {

class BottomStatusIndicator : public views::View {
class BottomStatusIndicator : public views::LabelButton,
public views::ButtonListener {
public:
enum class ContentType {
kNone,
kManagedDevice,
kAdbSideLoadingEnabled,
};

BottomStatusIndicator();
using TappedCallback = base::RepeatingClosure;

BottomStatusIndicator(TappedCallback on_tapped_callback);
BottomStatusIndicator(const BottomStatusIndicator&) = delete;
BottomStatusIndicator& operator=(const BottomStatusIndicator&) = delete;
~BottomStatusIndicator() override = default;
~BottomStatusIndicator() override;

void SetText(const base::string16& text, SkColor color);
void SetIcon(const gfx::VectorIcon& vector_icon,
AshColorProvider::ContentLayerType type);

void set_content_type(ContentType content_type) {
content_type_ = content_type;
}
ContentType content_type() const { return content_type_; }
void set_role_for_accessibility(ax::mojom::Role role) { role_ = role; }

// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;

// views::View:
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;

private:
views::Label* label_ = nullptr;
views::ImageView* icon_ = nullptr;

ContentType content_type_ = ContentType::kNone;
TappedCallback on_tapped_callback_;
ax::mojom::Role role_ = ax::mojom::Role::kStaticText;
};

} // namespace ash
Expand Down
123 changes: 104 additions & 19 deletions ash/login/ui/lock_contents_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include "base/strings/utf_string_conversions.h"
#include "chromeos/components/proximity_auth/public/mojom/auth_type.mojom.h"
#include "chromeos/constants/chromeos_features.h"
#include "chromeos/strings/grit/chromeos_strings.h"
#include "components/user_manager/user_type.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/l10n/l10n_util.h"
Expand All @@ -67,7 +68,6 @@
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/text_constants.h"
#include "ui/views/accessibility/view_accessibility.h"
Expand Down Expand Up @@ -111,6 +111,12 @@ constexpr int kMediumDensityDistanceBetweenAuthUserAndUsersPortraitDp = 84;
constexpr int kHorizontalPaddingAuthErrorBubbleDp = 8;
constexpr int kVerticalPaddingAuthErrorBubbleDp = 8;

// The font color of the bottom status indicator for enterprise management.
constexpr SkColor kBottomStatusManagedFontColor = gfx::kGoogleGrey200;

// The font color of the bottom status indicator for ADB warning.
constexpr SkColor kBottomStatusAdbFontColor = gfx::kGoogleRed300;

// Spacing between the bottom status indicator and the shelf.
constexpr int kBottomStatusIndicatorBottomMarginDp = 16;

Expand All @@ -120,6 +126,20 @@ constexpr int kBottomStatusIndicatorChildSpacingDp = 8;
// Spacing between child of LoginBaseBubbleView.
constexpr int kBubbleBetweenChildSpacingDp = 16;

// Width of the management pop-up.
constexpr int kManagementPopUpWidth = 400;

// Padding around the management bubble view.
constexpr int kBubblePaddingDp = 16;

// Size of the tooltip view info icon.
constexpr int kInfoIconSizeDp = 20;

// Maximum width of the management pop-up label.
constexpr int kManagementLabelMaxWidth =
kManagementPopUpWidth - 2 * kBubblePaddingDp - kInfoIconSizeDp -
kBubbleBetweenChildSpacingDp;

constexpr char kAuthErrorContainerName[] = "AuthErrorContainer";

// Sets the preferred width for |view| with an arbitrary height.
Expand Down Expand Up @@ -294,6 +314,41 @@ class LockContentsView::AuthErrorBubble : public LoginErrorBubble,
}
};

class LockContentsView::ManagementPopUp : public LoginTooltipView {
public:
ManagementPopUp(const base::string16& message, views::View* anchor_view)
: LoginTooltipView(message, anchor_view) {
views::BoxLayout* layout_manager =
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal,
gfx::Insets(kBubblePaddingDp), kBubbleBetweenChildSpacingDp));
layout_manager->set_cross_axis_alignment(
views::BoxLayout::CrossAxisAlignment::kStart);
label()->SetMaximumWidth(kManagementLabelMaxWidth);
SetVisible(false);
}

// LoginBaseBubbleView:
gfx::Size CalculatePreferredSize() const override {
gfx::Size size;
size.set_width(kManagementPopUpWidth);
size.set_height(GetHeightForWidth(kManagementPopUpWidth));
return size;
}

// LoginTooltipView:
gfx::Point CalculatePosition() override {
DCHECK(GetAnchorView());
gfx::Point top_center = GetAnchorView()->bounds().top_center();
gfx::Point position =
top_center - gfx::Vector2d(GetPreferredSize().width() / 2,
GetPreferredSize().height());
ConvertPointToTarget(GetAnchorView()->parent() /*source*/,
parent() /*target*/, &position);
return position;
}
};

class LockContentsView::AutoLoginUserActivityHandler
: public ui::UserActivityObserver {
public:
Expand Down Expand Up @@ -358,6 +413,10 @@ LoginTooltipView* LockContentsView::TestApi::tooltip_bubble() const {
return view_->tooltip_bubble_;
}

LoginTooltipView* LockContentsView::TestApi::management_bubble() const {
return view_->management_bubble_;
}

LoginErrorBubble* LockContentsView::TestApi::auth_error_bubble() const {
return view_->auth_error_bubble_;
}
Expand All @@ -384,6 +443,11 @@ views::View* LockContentsView::TestApi::bottom_status_indicator() const {
return view_->bottom_status_indicator_;
}

LockContentsView::BottomIndicatorState
LockContentsView::TestApi::bottom_status_indicator_status() const {
return view_->bottom_status_indicator_status_;
}

LoginExpandedPublicAccountView* LockContentsView::TestApi::expanded_view()
const {
return view_->expanded_view_;
Expand Down Expand Up @@ -499,7 +563,9 @@ LockContentsView::LockContentsView(

// The bottom status indicator view.
bottom_status_indicator_ =
AddChildView(std::make_unique<BottomStatusIndicator>());
AddChildView(std::make_unique<BottomStatusIndicator>(
base::BindRepeating(&LockContentsView::OnBottomStatusIndicatorTapped,
weak_ptr_factory_.GetWeakPtr())));
auto bottom_status_indicator_layout = std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal, gfx::Insets(),
kBottomStatusIndicatorChildSpacingDp);
Expand Down Expand Up @@ -536,6 +602,13 @@ LockContentsView::LockContentsView(
tooltip_bubble_ = AddChildView(std::make_unique<LoginTooltipView>(
base::UTF8ToUTF16("") /*message*/, nullptr /*anchor_view*/));

management_bubble_ = new ManagementPopUp(
l10n_util::GetStringFUTF16(IDS_ASH_LOGIN_ENTERPRISE_MANAGED_POP_UP,
ui::GetChromeOSDeviceName(),
base::UTF8ToUTF16(entreprise_domain_name)),
bottom_status_indicator_);
AddChildView(management_bubble_);

warning_banner_bubble_ = AddChildView(std::make_unique<LoginErrorBubble>());
warning_banner_bubble_->SetPersistent(true);

Expand Down Expand Up @@ -644,24 +717,26 @@ void LockContentsView::ShowEntrepriseDomainName(
bottom_status_indicator_->SetIcon(
kLoginScreenEnterpriseIcon,
AshColorProvider::ContentLayerType::kIconColorPrimary);
bottom_status_indicator_->SetText(
l10n_util::GetStringFUTF16(IDS_ASH_LOGIN_MANAGED_DEVICE_INDICATOR,
ui::GetChromeOSDeviceName(),
base::UTF8ToUTF16(entreprise_domain_name)),
gfx::kGoogleGrey200);
bottom_status_indicator_->set_content_type(
BottomStatusIndicator::ContentType::kManagedDevice);
bottom_status_indicator_->SetText(l10n_util::GetStringFUTF16(
IDS_ASH_LOGIN_MANAGED_DEVICE_INDICATOR, ui::GetChromeOSDeviceName(),
base::UTF8ToUTF16(entreprise_domain_name)));
bottom_status_indicator_->SetEnabledTextColors(kBottomStatusManagedFontColor);
bottom_status_indicator_->set_role_for_accessibility(
ax::mojom::Role::kButton);
bottom_status_indicator_status_ = BottomIndicatorState::kManagedDevice;
UpdateBottomStatusIndicatorVisibility();
}

void LockContentsView::ShowAdbEnabled() {
bottom_status_indicator_->SetIcon(
kLockScreenAlertIcon, AshColorProvider::ContentLayerType::kIconAlert);
bottom_status_indicator_->SetText(
l10n_util::GetStringUTF16(IDS_ASH_LOGIN_SCREEN_UNVERIFIED_CODE_WARNING),
gfx::kGoogleRed300);
bottom_status_indicator_->set_content_type(
BottomStatusIndicator::ContentType::kAdbSideLoadingEnabled);
l10n_util::GetStringUTF16(IDS_ASH_LOGIN_SCREEN_UNVERIFIED_CODE_WARNING));
bottom_status_indicator_->SetEnabledTextColors(kBottomStatusAdbFontColor);
bottom_status_indicator_->set_role_for_accessibility(
ax::mojom::Role::kStaticText);
bottom_status_indicator_status_ =
BottomIndicatorState::kAdbSideLoadingEnabled;
UpdateBottomStatusIndicatorVisibility();
}

Expand Down Expand Up @@ -1597,6 +1672,11 @@ void LockContentsView::LayoutBottomStatusIndicator() {
ShelfConfig::Get()->shelf_size() +
kBottomStatusIndicatorBottomMarginDp +
bottom_status_indicator_->height()));

// If the management bubble is currently displayed, we need to re-layout it as
// the bottom status indicator is its anchor view.
if (management_bubble_->GetVisible())
management_bubble_->Layout();
}

void LockContentsView::LayoutPublicSessionView() {
Expand Down Expand Up @@ -2156,15 +2236,20 @@ bool LockContentsView::GetSystemInfoVisibility() const {
}

void LockContentsView::UpdateBottomStatusIndicatorVisibility() {
bool visible =
bottom_status_indicator_->content_type() ==
BottomStatusIndicator::ContentType::kAdbSideLoadingEnabled ||
(bottom_status_indicator_->content_type() ==
BottomStatusIndicator::ContentType::kManagedDevice &&
!extension_ui_visible_);
bool visible = bottom_status_indicator_status_ ==
BottomIndicatorState::kAdbSideLoadingEnabled ||
(bottom_status_indicator_status_ ==
BottomIndicatorState::kManagedDevice &&
!extension_ui_visible_);
bottom_status_indicator_->SetVisible(visible);
}

void LockContentsView::OnBottomStatusIndicatorTapped() {
if (bottom_status_indicator_status_ != BottomIndicatorState::kManagedDevice)
return;
management_bubble_->Show();
}

BEGIN_METADATA(LockContentsView)
METADATA_PARENT_CLASS(NonAccessibleView)
END_METADATA()
Expand Down

0 comments on commit 194c4ac

Please sign in to comment.