Commit 1057c013 authored by Sergey Poromov's avatar Sergey Poromov Committed by Commit Bot

DLP: Add managed icon to toasts.

According to the mocks, Data Leak Protection toast should
contain a "managed" "building" icon on the left.
Adding this functionality to Toast as well as enforcing it
for DLP notifications.

See mocks: https://docs.google.com/presentation/d/1v0GM-lwHCznFJ6hnZlUH37eBOuAkJMw5Q6UnSkcKOgA/edit?hl=en#slide=id.g8f65759f6a_14_27

Bug: 1124651, 1096461
Change-Id: If815c55a3a9e011ea19f29b6cd95fb7aca2aeccc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2435390
Commit-Queue: Sergey Poromov <poromov@chromium.org>
Reviewed-by: default avatarYoshiki Iguchi <yoshiki@chromium.org>
Reviewed-by: default avatarAya Elsayed <ayaelattar@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811998}
parent 1eb99a01
......@@ -31,6 +31,7 @@ struct ASH_PUBLIC_EXPORT ToastData {
int32_t duration_ms;
base::Optional<base::string16> dismiss_text;
bool visible_on_lock_screen;
bool is_managed = false;
};
} // namespace ash
......
......@@ -92,7 +92,8 @@ void ToastManagerImpl::ShowLatest() {
overlay_ = std::make_unique<ToastOverlay>(
this, current_toast_data_->text, current_toast_data_->dismiss_text,
current_toast_data_->visible_on_lock_screen && locked_);
current_toast_data_->visible_on_lock_screen && locked_,
current_toast_data_->is_managed);
overlay_->Show(true);
if (current_toast_data_->duration_ms != ToastData::kInfiniteDuration) {
......
......@@ -7,6 +7,7 @@
#include "ash/keyboard/ui/keyboard_ui_controller.h"
#include "ash/public/cpp/ash_typography.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
......@@ -22,6 +23,7 @@
#include "ui/gfx/canvas.h"
#include "ui/gfx/font_list.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/background.h"
#include "ui/views/border.h"
......@@ -153,7 +155,8 @@ class ToastOverlayView : public views::View, public views::ButtonListener {
// This object is not owned by the views hierarchy or by the widget.
ToastOverlayView(ToastOverlay* overlay,
const base::string16& text,
const base::Optional<base::string16>& dismiss_text)
const base::Optional<base::string16>& dismiss_text,
const bool is_managed)
: overlay_(overlay) {
SetPaintToLayer();
SetBackground(
......@@ -166,9 +169,24 @@ class ToastOverlayView : public views::View, public views::ButtonListener {
auto* layout = SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal));
int icon_width = 0;
if (is_managed) {
auto* icon = new views::ImageView;
icon->SetImage(gfx::CreateVectorIcon(
kUnifiedMenuManagedIcon,
AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kIconColorPrimary)));
icon->SetBorder(views::CreateEmptyBorder(
gfx::Insets(kToastHorizontalSpacing, kToastHorizontalSpacing,
kToastHorizontalSpacing, /*right=*/0)));
AddChildView(icon);
icon_width = icon->GetPreferredSize().width() + kToastHorizontalSpacing;
}
auto* label = new ToastOverlayLabel(text);
AddChildView(label);
label->SetMaximumWidth(GetMaximumSize().width());
label->SetMaximumWidth(GetMaximumSize().width() - icon_width);
layout->SetFlexForView(label, 1);
if (!dismiss_text.has_value())
......@@ -183,7 +201,7 @@ class ToastOverlayView : public views::View, public views::ButtonListener {
std::min(button_->GetPreferredSize().width(), kToastButtonMaximumWidth);
button_->SetMaxSize(gfx::Size(button_width, GetMaximumSize().height()));
label->SetMaximumWidth(GetMaximumSize().width() - button_width -
kToastHorizontalSpacing * 2 -
icon_width - kToastHorizontalSpacing * 2 -
kToastHorizontalSpacing * 2);
AddChildView(button_);
}
......@@ -220,12 +238,13 @@ class ToastOverlayView : public views::View, public views::ButtonListener {
ToastOverlay::ToastOverlay(Delegate* delegate,
const base::string16& text,
base::Optional<base::string16> dismiss_text,
bool show_on_lock_screen)
bool show_on_lock_screen,
bool is_managed)
: delegate_(delegate),
text_(text),
dismiss_text_(dismiss_text),
overlay_widget_(new views::Widget),
overlay_view_(new ToastOverlayView(this, text, dismiss_text)),
overlay_view_(new ToastOverlayView(this, text, dismiss_text, is_managed)),
display_observer_(std::make_unique<ToastDisplayObserver>(this)),
widget_size_(overlay_view_->GetPreferredSize()) {
views::Widget::InitParams params;
......
......@@ -46,11 +46,12 @@ class ASH_EXPORT ToastOverlay : public ui::ImplicitAnimationObserver,
// |dismiss_text| is the message for the button to dismiss the toast message.
// If |dismiss_text| is null, no dismiss button will be shown. If
// |dismiss_text| has a value but the string is empty, the default text is
// used.
// used. If |is_managed| is true, a managed icon will be added to the toast.
ToastOverlay(Delegate* delegate,
const base::string16& text,
base::Optional<base::string16> dismiss_text,
bool show_on_lock_screen = false);
bool show_on_lock_screen,
bool is_managed);
~ToastOverlay() override;
// Shows or hides the overlay.
......
......@@ -23,6 +23,7 @@ void ShowDlpPrintDisabledToast() {
ash::ToastData toast(
kPrintToastId, l10n_util::GetStringUTF16(IDS_POLICY_DLP_PRINTING_BLOCKED),
kPrintToastDurationMs, base::nullopt);
toast.is_managed = true;
ash::ToastManager::Get()->Show(toast);
}
......
......@@ -79,8 +79,8 @@ bool EnterpriseClipboardDlpController::IsDataReadAllowed(
void EnterpriseClipboardDlpController::ShowBlockToast(
const base::string16& text) const {
ash::ToastData toast(kToastId, text, kToastDurationMs,
base::Optional<base::string16>());
ash::ToastData toast(kToastId, text, kToastDurationMs, base::nullopt);
toast.is_managed = true;
ash::ToastManager::Get()->Show(toast);
}
......
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