Skip to content

Commit

Permalink
borealis: Add a "beta" label to the borealis installer
Browse files Browse the repository at this point in the history
This label indicates to the user that "Steam for Chromebook" is still in
beta.

Bug: b:276392572
Change-Id: If0456fe9f21641f4f5fac066879e8437113070ed
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4564895
Reviewed-by: Chloe Pelling <cpelling@google.com>
Commit-Queue: Nic Hollingum <hollingum@google.com>
Cr-Commit-Position: refs/heads/main@{#1150364}
  • Loading branch information
Nicholas Hollingum authored and Chromium LUCI CQ committed May 30, 2023
1 parent 9693298 commit ea75b74
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 0 deletions.
3 changes: 3 additions & 0 deletions chrome/app/chromeos_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -6166,6 +6166,9 @@ Permissions you've already given to websites and apps may apply to this account.
<message name="IDS_BOREALIS_INSTALLER_ERROR_RETRY" desc="Button for Steam (noun, name of app) installer to retry after failing.">
Retry
</message>
<message name="IDS_BOREALIS_BETA_BADGE" desc="Badge text indicating that borealis (steam on chromeos) is a beta product, i.e. it is still under development.">
Beta
</message>
<message name="IDS_BOREALIS_CLIENT_UNINSTALL_CONFIRM_BODY" desc="Confirmation dialog for uninstalling Steam (name of app).">
Any games and apps installed via Steam will also be removed from this device
</message>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3d7f342ba8c692eabf5a899c6fc824fd6f34e1f6
2 changes: 2 additions & 0 deletions chrome/browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2730,6 +2730,8 @@ static_library("ui") {
"views/apps/chrome_native_app_window_views_aura_ash.h",
"views/arc_app_dialog_view.cc",
"views/arc_data_removal_dialog_view.cc",
"views/borealis/borealis_beta_badge.cc",
"views/borealis/borealis_beta_badge.h",
"views/borealis/borealis_installer_disallowed_dialog.cc",
"views/borealis/borealis_installer_disallowed_dialog.h",
"views/borealis/borealis_installer_error_dialog.cc",
Expand Down
90 changes: 90 additions & 0 deletions chrome/browser/ui/views/borealis/borealis_beta_badge.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/views/borealis/borealis_beta_badge.h"

#include <string>

#include "base/i18n/rtl.h"
#include "cc/paint/paint_flags.h"
#include "chrome/grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/chromeos/styles/cros_tokens_color_mappings.h"
#include "ui/color/color_id.h"
#include "ui/color/color_provider.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/font_list.h"
#include "ui/gfx/geometry/outsets.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/text_utils.h"

namespace views {

namespace {
// Padding that appears around the "Beta" label.
gfx::Outsets kInternalPadding = gfx::Outsets::VH(4, 10);

// The corners of the label are rounded,
int kCornerRadius = 10;

// Colors used by the badge.
ui::ColorId kTextColor = cros_tokens::LegacySemanticColorIds::kColorSelection;
ui::ColorId kBackgroundColor =
cros_tokens::LegacySemanticColorIds::kHighlightColor;

gfx::FontList GetFont() {
// TODO(b/284389804): Use TypographyToken::kCrosButton1
return gfx::FontList({"Google Sans", "Roboto"}, gfx::Font::NORMAL, 14,
gfx::Font::Weight::MEDIUM);
}

} // namespace

BorealisBetaBadge::BorealisBetaBadge() = default;

BorealisBetaBadge::~BorealisBetaBadge() = default;

std::u16string BorealisBetaBadge::GetText() const {
return l10n_util::GetStringUTF16(IDS_BOREALIS_BETA_BADGE);
}

gfx::Size BorealisBetaBadge::CalculatePreferredSize() const {
gfx::Rect preferred(gfx::GetStringSize(GetText(), GetFont()));
preferred.Outset(kInternalPadding);
return preferred.size();
}

void BorealisBetaBadge::OnPaint(gfx::Canvas* canvas) {
gfx::Size text_size = gfx::GetStringSize(GetText(), GetFont());
// The text is offset from the top-left corner by the inset amount
gfx::Rect badge_text_bounds{
gfx::Point(kInternalPadding.left(), kInternalPadding.top()), text_size};
// ...depending on the side text is written on.
if (base::i18n::IsRTL()) {
badge_text_bounds.set_x(GetMirroredXForRect(badge_text_bounds));
}

const ui::ColorProvider* color_provider = GetColorProvider();

// Render the badge itself.
gfx::Rect surrounding(badge_text_bounds);
surrounding.Outset(kInternalPadding);
cc::PaintFlags flags;
flags.setColor(color_provider->GetColor(kBackgroundColor));
canvas->DrawRoundRect(surrounding, kCornerRadius, flags);

// Render the badge text.
canvas->DrawStringRect(GetText(), GetFont(),
color_provider->GetColor(kTextColor),
badge_text_bounds);
}

BEGIN_METADATA(BorealisBetaBadge, View)
ADD_READONLY_PROPERTY_METADATA(std::u16string, Text)
END_METADATA

} // namespace views
36 changes: 36 additions & 0 deletions chrome/browser/ui/views/borealis/borealis_beta_badge.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_VIEWS_BOREALIS_BOREALIS_BETA_BADGE_H_
#define CHROME_BROWSER_UI_VIEWS_BOREALIS_BOREALIS_BETA_BADGE_H_

#include <string>

#include "ui/views/view.h"
#include "ui/views/views_export.h"

namespace views {

// Badge used to signify borealis' beta-ness on various UI surfaces.
class VIEWS_EXPORT BorealisBetaBadge : public View {
public:
METADATA_HEADER(BorealisBetaBadge);

BorealisBetaBadge();
~BorealisBetaBadge() override;

// Not copyable or movable.
BorealisBetaBadge(const BorealisBetaBadge&) = delete;
BorealisBetaBadge& operator=(const BorealisBetaBadge&) = delete;

std::u16string GetText() const;

// View overrides.
gfx::Size CalculatePreferredSize() const override;
void OnPaint(gfx::Canvas* canvas) override;
};

} // namespace views

#endif // CHROME_BROWSER_UI_VIEWS_BOREALIS_BOREALIS_BETA_BADGE_H_
8 changes: 8 additions & 0 deletions chrome/browser/ui/views/borealis/borealis_installer_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "chrome/browser/ash/borealis/borealis_util.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_navigator_params.h"
#include "chrome/browser/ui/views/borealis/borealis_beta_badge.h"
#include "chrome/browser/ui/views/borealis/borealis_installer_disallowed_dialog.h"
#include "chrome/browser/ui/views/borealis/borealis_installer_error_dialog.h"
#include "chrome/browser/ui/views/borealis/borealis_splash_screen_view.h"
Expand Down Expand Up @@ -161,6 +162,10 @@ BorealisInstallerView::BorealisInstallerView(Profile* profile)
primary_message_label_->SetMaximumWidth(264);
left_container_view->AddChildView(primary_message_label_.get());

beta_badge_ = left_container_view->AddChildView(
std::make_unique<views::BorealisBetaBadge>());
beta_badge_->SetProperty(views::kMarginsKey, gfx::Insets::TLBR(16, 0, 0, 0));

secondary_message_label_ = new views::Label(
GetSecondaryMessage(), views::style::CONTEXT_DIALOG_BODY_TEXT,
views::style::STYLE_SECONDARY);
Expand Down Expand Up @@ -416,6 +421,9 @@ void BorealisInstallerView::OnStateUpdated() {
const bool progress_bar_visible = state_ == State::kInstalling;
progress_bar_->SetVisible(progress_bar_visible);

const bool beta_badge_visible = state_ != State::kCompleted;
beta_badge_->SetVisible(beta_badge_visible);

DialogModelChanged();
primary_message_label_->NotifyAccessibilityEvent(
ax::mojom::Event::kLiveRegionChanged,
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/ui/views/borealis/borealis_installer_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "ui/views/window/dialog_delegate.h"

namespace views {
class BorealisBetaBadge;
class BoxLayout;
class ImageView;
class Label;
Expand Down Expand Up @@ -108,6 +109,7 @@ class BorealisInstallerView : public views::DialogDelegateView,
raw_ptr<Profile, ExperimentalAsh> profile_ = nullptr;
raw_ptr<views::Label, ExperimentalAsh> primary_message_label_ = nullptr;
raw_ptr<views::Label, ExperimentalAsh> secondary_message_label_ = nullptr;
raw_ptr<views::BorealisBetaBadge, ExperimentalAsh> beta_badge_ = nullptr;
raw_ptr<views::ProgressBar, ExperimentalAsh> progress_bar_ = nullptr;
raw_ptr<views::Label, ExperimentalAsh>
installation_progress_percentage_label_ = nullptr;
Expand Down

0 comments on commit ea75b74

Please sign in to comment.