Add a progress bar corner radius setter
Add a constructor parameter for the corner radius on the progress bar so we can set a custom corner radius in a follow up CL. Change-Id: I9309a66dbc4ea215bb3949e5f6dbe08e56087892 Bug: b/286931547 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4974822 Commit-Queue: Andrew Pantera <andp@chromium.org> Reviewed-by: Cait Phillips <caitkp@chromium.org> Reviewed-by: Allen Bauer <kylixrd@chromium.org> Reviewed-by: Tommy Steimel <steimel@chromium.org> Reviewed-by: Luke Halliwell <halliwell@chromium.org> Cr-Commit-Position: refs/heads/main@{#1225935}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
42201200e0
commit
ed2a47c23d
ash
glanceables
system
chrome/browser
ash
arc
nearby_share
ui
views
bruschetta
download
location_bar
cookie_controls
payments
plugin_vm
webauthn
webid
chromecast/graphics
components/media_message_center
ui
message_center
views
@ -31,8 +31,9 @@ GlanceablesProgressBarView::GlanceablesProgressBarView() {
|
||||
SetPreferredSize(kProgressBarContainerPreferredSize);
|
||||
SetProperty(views::kMarginsKey, kProgressBarContainerMargins);
|
||||
|
||||
progress_bar_ = AddChildView(std::make_unique<views::ProgressBar>(
|
||||
kProgressBarThickness, /*allow_round_corner=*/false));
|
||||
progress_bar_ = AddChildView(std::make_unique<views::ProgressBar>());
|
||||
progress_bar_->SetPreferredHeight(kProgressBarThickness);
|
||||
progress_bar_->SetPreferredCornerRadii(absl::nullopt);
|
||||
progress_bar_->SetID(base::to_underlying(GlanceablesViewId::kProgressBar));
|
||||
progress_bar_->SetBackgroundColorId(cros_tokens::kCrosSysSystemOnBase);
|
||||
progress_bar_->SetForegroundColorId(cros_tokens::kCrosSysPrimary);
|
||||
|
@ -84,8 +84,8 @@ FocusModeCountdownView::FocusModeCountdownView(bool include_end_button)
|
||||
|
||||
// TODO(b/286931547): Timer Progress Bar.
|
||||
progress_bar_ =
|
||||
timer_container->AddChildView(std::make_unique<views::ProgressBar>(
|
||||
/*preferred_height=*/kBarHeight, /*allow_round_corner*/ true));
|
||||
timer_container->AddChildView(std::make_unique<views::ProgressBar>());
|
||||
progress_bar_->SetPreferredHeight(kBarHeight);
|
||||
progress_bar_->SetBackgroundColorId(cros_tokens::kCrosSysSystemOnBase);
|
||||
progress_bar_->SetForegroundColorId(cros_tokens::kCrosSysPrimary);
|
||||
progress_bar_->SetBorder(views::CreateEmptyBorder(
|
||||
|
@ -40,6 +40,7 @@ class ASH_EXPORT FocusModeCountdownView : public views::FlexLayoutView {
|
||||
|
||||
private:
|
||||
friend class FocusModeCountdownViewTest;
|
||||
|
||||
// The main timer label, displays the amount of time left in the focus
|
||||
// session.
|
||||
raw_ptr<views::Label, ExperimentalAsh> time_remaining_label_ = nullptr;
|
||||
|
@ -56,7 +56,8 @@ PhoneHubInterstitialView::PhoneHubInterstitialView(bool show_progress,
|
||||
progress_bar_container->SetMainAxisAlignment(
|
||||
views::BoxLayout::MainAxisAlignment::kCenter);
|
||||
progress_bar_ = progress_bar_container->AddChildView(
|
||||
std::make_unique<views::ProgressBar>(2));
|
||||
std::make_unique<views::ProgressBar>());
|
||||
progress_bar_->SetPreferredHeight(2);
|
||||
progress_bar_->SetForegroundColor(color_provider->GetContentLayerColor(
|
||||
AshColorProvider::ContentLayerType::kIconColorProminent));
|
||||
progress_bar_->SetValue(-1.0);
|
||||
|
@ -235,9 +235,9 @@ void TrayDetailedView::Reset() {
|
||||
void TrayDetailedView::ShowProgress(double value, bool visible) {
|
||||
DCHECK(tri_view_);
|
||||
if (!progress_bar_) {
|
||||
progress_bar_ = AddChildViewAt(
|
||||
std::make_unique<views::ProgressBar>(kTitleRowProgressBarHeight),
|
||||
kTitleRowProgressBarIndex + 1);
|
||||
progress_bar_ = AddChildViewAt(std::make_unique<views::ProgressBar>(),
|
||||
kTitleRowProgressBarIndex + 1);
|
||||
progress_bar_->SetPreferredHeight(kTitleRowProgressBarHeight);
|
||||
progress_bar_->GetViewAccessibility().OverrideName(
|
||||
progress_bar_accessible_name_.value_or(l10n_util::GetStringUTF16(
|
||||
IDS_ASH_STATUS_TRAY_PROGRESS_BAR_ACCESSIBLE_NAME)));
|
||||
|
@ -60,8 +60,8 @@ ProgressBarDialogView::ProgressBarDialogView(bool is_multiple_files)
|
||||
message_label_->SetVerticalAlignment(gfx::ALIGN_TOP);
|
||||
AddChildView(message_label_.get());
|
||||
|
||||
progress_bar_ = AddChildView(std::make_unique<views::ProgressBar>(
|
||||
/*preferred_height=*/kProgressBarHeight));
|
||||
progress_bar_ = AddChildView(std::make_unique<views::ProgressBar>());
|
||||
progress_bar_->SetPreferredHeight(kProgressBarHeight);
|
||||
progress_bar_->SetValue(0.01); // set small initial value.
|
||||
progress_bar_->SetPreferredSize(
|
||||
gfx::Size(kProgressBarWidth, kProgressBarHeight));
|
||||
|
@ -163,7 +163,8 @@ BruschettaInstallerView::BruschettaInstallerView(Profile* profile,
|
||||
learn_more_url_));
|
||||
secondary_message_container_view->AddChildView(link_label_.get());
|
||||
|
||||
progress_bar_ = new views::ProgressBar(kProgressBarHeight);
|
||||
progress_bar_ = new views::ProgressBar();
|
||||
progress_bar_->SetPreferredHeight(kProgressBarHeight);
|
||||
progress_bar_->SetProperty(
|
||||
views::kMarginsKey,
|
||||
gfx::Insets::TLBR(kProgressBarTopMargin - kProgressBarHeight, 0, 0, 0));
|
||||
|
@ -510,9 +510,9 @@ DownloadBubbleRowView::DownloadBubbleRowView(
|
||||
gfx::Size(kNumColumns, 1));
|
||||
progress_bar_holder_->SetProperty(views::kTableHorizAlignKey,
|
||||
views::LayoutAlignment::kStretch);
|
||||
progress_bar_ =
|
||||
progress_bar_holder_->AddChildView(std::make_unique<views::ProgressBar>(
|
||||
/*preferred_height=*/kProgressBarHeight));
|
||||
progress_bar_ = progress_bar_holder_->AddChildView(
|
||||
std::make_unique<views::ProgressBar>());
|
||||
progress_bar_->SetPreferredHeight(kProgressBarHeight);
|
||||
progress_bar_->SetBorder(views::CreateEmptyBorder(
|
||||
gfx::Insets::TLBR(ChromeLayoutProvider::Get()->GetDistanceMetric(
|
||||
views::DISTANCE_RELATED_CONTROL_VERTICAL),
|
||||
|
@ -573,8 +573,8 @@ void DownloadBubbleSecurityView::AddProgressBar() {
|
||||
progress_bar_holder->SetProperty(views::kTableHorizAlignKey,
|
||||
views::LayoutAlignment::kStretch);
|
||||
progress_bar_ =
|
||||
progress_bar_holder->AddChildView(std::make_unique<views::ProgressBar>(
|
||||
/*preferred_height=*/kProgressBarHeight));
|
||||
progress_bar_holder->AddChildView(std::make_unique<views::ProgressBar>());
|
||||
progress_bar_->SetPreferredHeight(kProgressBarHeight);
|
||||
progress_bar_->SetProperty(
|
||||
views::kMarginsKey,
|
||||
gfx::Insets().set_top(ChromeLayoutProvider::Get()->GetDistanceMetric(
|
||||
|
@ -376,8 +376,9 @@ CookieControlsBubbleViewController::InitReloadingView(
|
||||
reloading_view->SetLayoutManager(std::make_unique<views::BoxLayout>(
|
||||
views::BoxLayout::Orientation::kVertical));
|
||||
|
||||
auto progress_bar = std::make_unique<views::ProgressBar>(
|
||||
kProgressBarHeight, /*allow_round_corner=*/false);
|
||||
auto progress_bar = std::make_unique<views::ProgressBar>();
|
||||
progress_bar->SetPreferredHeight(kProgressBarHeight);
|
||||
progress_bar->SetPreferredCornerRadii(absl::nullopt);
|
||||
progress_bar->SetValue(-1);
|
||||
|
||||
auto reloading_content = std::make_unique<views::View>();
|
||||
|
@ -264,7 +264,8 @@ void PaymentHandlerWebFlowViewController::FillContentView(
|
||||
// Add the progress bar to the separator container. The progress bar
|
||||
// colors will be set in PopulateSheetHeaderView.
|
||||
progress_bar_ = header_content_separator_container()->AddChildView(
|
||||
std::make_unique<views::ProgressBar>(/*preferred_height=*/2));
|
||||
std::make_unique<views::ProgressBar>());
|
||||
progress_bar_->SetPreferredHeight(2);
|
||||
if (!spec()->IsPaymentHandlerMinimalHeaderUXEnabled()) {
|
||||
// Prior to minimal UX, the separator container used a Separator view,
|
||||
// which uses the Chrome theme color which may not match the header color.
|
||||
|
@ -85,8 +85,9 @@ END_METADATA
|
||||
|
||||
std::unique_ptr<views::ProgressBar>
|
||||
CreateSecurePaymentConfirmationProgressBarView() {
|
||||
auto progress_bar = std::make_unique<views::ProgressBar>(
|
||||
kProgressBarHeight, /*allow_round_corner=*/false);
|
||||
auto progress_bar = std::make_unique<views::ProgressBar>();
|
||||
progress_bar->SetPreferredHeight(kProgressBarHeight);
|
||||
progress_bar->SetPreferredCornerRadii(absl::nullopt);
|
||||
progress_bar->SetValue(-1); // infinite animation.
|
||||
progress_bar->SetBackgroundColor(SK_ColorTRANSPARENT);
|
||||
progress_bar->SetPreferredSize(
|
||||
|
@ -175,7 +175,8 @@ PluginVmInstallerView::PluginVmInstallerView(Profile* profile)
|
||||
learn_more_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
|
||||
message_container_view->AddChildView(learn_more_link_.get());
|
||||
|
||||
progress_bar_ = new views::ProgressBar(kProgressBarHeight);
|
||||
progress_bar_ = new views::ProgressBar();
|
||||
progress_bar_->SetPreferredHeight(kProgressBarHeight);
|
||||
progress_bar_->SetProperty(
|
||||
views::kMarginsKey,
|
||||
gfx::Insets::TLBR(kProgressBarTopMargin - kProgressBarHeight, 0, 0, 0));
|
||||
|
@ -129,9 +129,10 @@ AuthenticatorRequestSheetView::CreateIllustrationWithOverlays() {
|
||||
|
||||
if (model()->IsActivityIndicatorVisible()) {
|
||||
constexpr int kActivityIndicatorHeight = 4;
|
||||
auto activity_indicator = std::make_unique<views::ProgressBar>(
|
||||
kActivityIndicatorHeight, false /* allow_round_corner */);
|
||||
activity_indicator->SetValue(-1 /* inifinite animation */);
|
||||
auto activity_indicator = std::make_unique<views::ProgressBar>();
|
||||
activity_indicator->SetPreferredHeight(kActivityIndicatorHeight);
|
||||
activity_indicator->SetPreferredCornerRadii(absl::nullopt);
|
||||
activity_indicator->SetValue(-1 /* infinite animation */);
|
||||
activity_indicator->SetBackgroundColor(SK_ColorTRANSPARENT);
|
||||
activity_indicator->SetPreferredSize(
|
||||
gfx::Size(dialog_width, kActivityIndicatorHeight));
|
||||
|
@ -600,7 +600,8 @@ void AccountSelectionBubbleView::ShowVerifyingSheet(
|
||||
|
||||
RemoveNonHeaderChildViews();
|
||||
views::ProgressBar* const progress_bar =
|
||||
AddChildView(std::make_unique<views::ProgressBar>(kProgressBarHeight));
|
||||
AddChildView(std::make_unique<views::ProgressBar>());
|
||||
progress_bar->SetPreferredHeight(kProgressBarHeight);
|
||||
// Use an infinite animation: SetValue(-1).
|
||||
progress_bar->SetValue(-1);
|
||||
progress_bar->SetBackgroundColor(SK_ColorLTGRAY);
|
||||
|
@ -18,7 +18,8 @@ TEST_F(CastViewsTest, ProgressBar) {
|
||||
std::make_unique<CastWindowManagerAura>(true /* enable input */);
|
||||
gfx::Rect bounds = window_manager->GetRootWindow()->bounds();
|
||||
|
||||
views::ProgressBar* progress_bar = new views::ProgressBar(bounds.height());
|
||||
views::ProgressBar* progress_bar = new views::ProgressBar();
|
||||
progress_bar->SetPreferredHeight(bounds.height());
|
||||
progress_bar->SetValue(0.5);
|
||||
|
||||
// Create the window. We close the window by deleting it, so we take
|
||||
|
@ -44,9 +44,10 @@ MediaControlsProgressView::MediaControlsProgressView(
|
||||
is_modern_notification_ ? kModernProgressViewInsets : kProgressViewInsets,
|
||||
kProgressBarAndTimeSpacing));
|
||||
|
||||
progress_bar_ = AddChildView(std::make_unique<views::ProgressBar>(
|
||||
is_modern_notification_ ? kModernProgressBarHeight : kProgressBarHeight,
|
||||
false));
|
||||
progress_bar_ = AddChildView(std::make_unique<views::ProgressBar>());
|
||||
progress_bar_->SetPreferredHeight(
|
||||
is_modern_notification_ ? kModernProgressBarHeight : kProgressBarHeight);
|
||||
progress_bar_->SetPreferredCornerRadii(absl::nullopt);
|
||||
|
||||
// Font list for text views.
|
||||
gfx::Font default_font;
|
||||
|
@ -525,9 +525,9 @@ void NotificationViewBase::CreateOrUpdateProgressBarView(
|
||||
DCHECK(left_content_);
|
||||
|
||||
if (!progress_bar_view_) {
|
||||
auto progress_bar_view =
|
||||
std::make_unique<views::ProgressBar>(kProgressBarHeight,
|
||||
/* allow_round_corner */ false);
|
||||
auto progress_bar_view = std::make_unique<views::ProgressBar>();
|
||||
progress_bar_view->SetPreferredHeight(kProgressBarHeight);
|
||||
progress_bar_view->SetPreferredCornerRadii(absl::nullopt);
|
||||
progress_bar_view->SetBorder(views::CreateEmptyBorder(
|
||||
gfx::Insets::TLBR(kProgressBarTopPadding, 0, 0, 0)));
|
||||
progress_bar_view_ = AddViewToLeftContent(std::move(progress_bar_view));
|
||||
|
@ -130,8 +130,9 @@ BubbleFrameView::BubbleFrameView(const gfx::Insets& title_margins,
|
||||
close->SetVisible(false);
|
||||
close_ = AddChildView(std::move(close));
|
||||
|
||||
auto progress_indicator = std::make_unique<ProgressBar>(
|
||||
kProgressIndicatorHeight, /*allow_round_corner=*/false);
|
||||
auto progress_indicator = std::make_unique<ProgressBar>();
|
||||
progress_indicator->SetPreferredHeight(kProgressIndicatorHeight);
|
||||
progress_indicator->SetPreferredCornerRadii(absl::nullopt);
|
||||
progress_indicator->SetBackgroundColor(SK_ColorTRANSPARENT);
|
||||
progress_indicator->SetVisible(false);
|
||||
progress_indicator->GetViewAccessibility().OverrideIsIgnored(true);
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include "base/check_op.h"
|
||||
#include "base/i18n/number_formatting.h"
|
||||
#include "cc/paint/paint_flags.h"
|
||||
#include "third_party/skia/include/core/SkPath.h"
|
||||
#include "third_party/skia/include/core/SkRRect.h"
|
||||
#include "third_party/skia/include/effects/SkGradientShader.h"
|
||||
#include "ui/accessibility/ax_enums.mojom.h"
|
||||
#include "ui/accessibility/ax_node_data.h"
|
||||
@ -29,27 +29,27 @@ namespace views {
|
||||
|
||||
namespace {
|
||||
|
||||
// In DP, the amount to round the corners of the progress bar (both bg and
|
||||
// fg, aka slice).
|
||||
constexpr int kCornerRadius = 3;
|
||||
constexpr int kSmallCornerRadius = 1;
|
||||
|
||||
// Adds a rectangle to the path. The corners will be rounded with regular corner
|
||||
// radius if the progress bar height is larger than the regular corner radius.
|
||||
// Otherwise the corners will be rounded with the small corner radius if there
|
||||
// is room for it.
|
||||
void AddPossiblyRoundRectToPath(const gfx::Rect& rectangle,
|
||||
bool allow_round_corner,
|
||||
SkPath* path) {
|
||||
if (!allow_round_corner || rectangle.height() < kSmallCornerRadius) {
|
||||
// Adds a rectangle to the path.
|
||||
void AddPossiblyRoundRectToPath(
|
||||
const gfx::Rect& rectangle,
|
||||
const gfx::RoundedCornersF& preferred_corner_radii,
|
||||
SkPath* path) {
|
||||
if (preferred_corner_radii.IsEmpty() || rectangle.height() == 0) {
|
||||
path->addRect(gfx::RectToSkRect(rectangle));
|
||||
} else if (rectangle.height() < kCornerRadius) {
|
||||
path->addRoundRect(gfx::RectToSkRect(rectangle), kSmallCornerRadius,
|
||||
kSmallCornerRadius);
|
||||
} else {
|
||||
path->addRoundRect(gfx::RectToSkRect(rectangle), kCornerRadius,
|
||||
kCornerRadius);
|
||||
return;
|
||||
}
|
||||
SkVector radii[4] = {{preferred_corner_radii.upper_left(),
|
||||
preferred_corner_radii.upper_left()},
|
||||
{preferred_corner_radii.upper_right(),
|
||||
preferred_corner_radii.upper_right()},
|
||||
{preferred_corner_radii.lower_right(),
|
||||
preferred_corner_radii.lower_right()},
|
||||
{preferred_corner_radii.lower_left(),
|
||||
preferred_corner_radii.lower_left()}};
|
||||
|
||||
SkRRect rr;
|
||||
rr.setRectRadii(gfx::RectToSkRect(rectangle), radii);
|
||||
path->addRRect(rr);
|
||||
}
|
||||
|
||||
int RoundToPercent(double fractional_value) {
|
||||
@ -58,9 +58,7 @@ int RoundToPercent(double fractional_value) {
|
||||
|
||||
} // namespace
|
||||
|
||||
ProgressBar::ProgressBar(int preferred_height, bool allow_round_corner)
|
||||
: preferred_height_(preferred_height),
|
||||
allow_round_corner_(allow_round_corner) {
|
||||
ProgressBar::ProgressBar() {
|
||||
SetFlipCanvasOnPaintForRTLUI(true);
|
||||
SetAccessibilityProperties(ax::mojom::Role::kProgressIndicator);
|
||||
}
|
||||
@ -101,8 +99,8 @@ void ProgressBar::OnPaint(gfx::Canvas* canvas) {
|
||||
|
||||
// Draw background.
|
||||
SkPath background_path;
|
||||
AddPossiblyRoundRectToPath(content_bounds, allow_round_corner_,
|
||||
&background_path);
|
||||
gfx::RoundedCornersF rounded_corners = GetPreferredCornerRadii();
|
||||
AddPossiblyRoundRectToPath(content_bounds, rounded_corners, &background_path);
|
||||
cc::PaintFlags background_flags;
|
||||
background_flags.setStyle(cc::PaintFlags::kFill_Style);
|
||||
background_flags.setAntiAlias(true);
|
||||
@ -119,7 +117,7 @@ void ProgressBar::OnPaint(gfx::Canvas* canvas) {
|
||||
|
||||
gfx::Rect slice_bounds = content_bounds;
|
||||
slice_bounds.set_width(slice_width);
|
||||
AddPossiblyRoundRectToPath(slice_bounds, allow_round_corner_, &slice_path);
|
||||
AddPossiblyRoundRectToPath(slice_bounds, rounded_corners, &slice_path);
|
||||
|
||||
cc::PaintFlags slice_flags;
|
||||
slice_flags.setStyle(cc::PaintFlags::kFill_Style);
|
||||
@ -227,6 +225,41 @@ void ProgressBar::SetBackgroundColorId(absl::optional<ui::ColorId> color_id) {
|
||||
OnPropertyChanged(&background_color_id_, kPropertyEffectsPaint);
|
||||
}
|
||||
|
||||
int ProgressBar::GetPreferredHeight() const {
|
||||
return preferred_height_;
|
||||
}
|
||||
|
||||
void ProgressBar::SetPreferredHeight(const int preferred_height) {
|
||||
if (preferred_height_ == preferred_height) {
|
||||
return;
|
||||
}
|
||||
preferred_height_ = preferred_height;
|
||||
OnPropertyChanged(&preferred_height_, kPropertyEffectsPreferredSizeChanged);
|
||||
}
|
||||
|
||||
gfx::RoundedCornersF ProgressBar::GetPreferredCornerRadii() const {
|
||||
if (!preferred_corner_radii_) {
|
||||
return gfx::RoundedCornersF(0);
|
||||
}
|
||||
const float max_radius = GetContentsBounds().height();
|
||||
|
||||
// No corner should have a radius greater than the height of the bar.
|
||||
return gfx::RoundedCornersF(
|
||||
std::min(max_radius, preferred_corner_radii_->upper_left()),
|
||||
std::min(max_radius, preferred_corner_radii_->upper_right()),
|
||||
std::min(max_radius, preferred_corner_radii_->lower_right()),
|
||||
std::min(max_radius, preferred_corner_radii_->lower_left()));
|
||||
}
|
||||
|
||||
void ProgressBar::SetPreferredCornerRadii(
|
||||
const absl::optional<gfx::RoundedCornersF> preferred_corner_radii) {
|
||||
if (preferred_corner_radii_ == preferred_corner_radii) {
|
||||
return;
|
||||
}
|
||||
preferred_corner_radii_ = preferred_corner_radii;
|
||||
OnPropertyChanged(&preferred_corner_radii_, kPropertyEffectsPaint);
|
||||
}
|
||||
|
||||
void ProgressBar::AnimationProgressed(const gfx::Animation* animation) {
|
||||
DCHECK_EQ(animation, indeterminate_bar_animation_.get());
|
||||
DCHECK(IsIndeterminate());
|
||||
@ -250,8 +283,8 @@ void ProgressBar::OnPaintIndeterminate(gfx::Canvas* canvas) {
|
||||
|
||||
// Draw background.
|
||||
SkPath background_path;
|
||||
AddPossiblyRoundRectToPath(content_bounds, allow_round_corner_,
|
||||
&background_path);
|
||||
gfx::RoundedCornersF rounded_corners = GetPreferredCornerRadii();
|
||||
AddPossiblyRoundRectToPath(content_bounds, rounded_corners, &background_path);
|
||||
cc::PaintFlags background_flags;
|
||||
background_flags.setStyle(cc::PaintFlags::kFill_Style);
|
||||
background_flags.setAntiAlias(true);
|
||||
@ -295,10 +328,10 @@ void ProgressBar::OnPaintIndeterminate(gfx::Canvas* canvas) {
|
||||
gfx::Rect slice_bounds = content_bounds;
|
||||
slice_bounds.set_x(content_bounds.x() + bar1_start_x);
|
||||
slice_bounds.set_width(bar1_end_x - bar1_start_x);
|
||||
AddPossiblyRoundRectToPath(slice_bounds, allow_round_corner_, &slice_path);
|
||||
AddPossiblyRoundRectToPath(slice_bounds, rounded_corners, &slice_path);
|
||||
slice_bounds.set_x(content_bounds.x() + bar2_start_x);
|
||||
slice_bounds.set_width(bar2_end_x - bar2_start_x);
|
||||
AddPossiblyRoundRectToPath(slice_bounds, allow_round_corner_, &slice_path);
|
||||
AddPossiblyRoundRectToPath(slice_bounds, rounded_corners, &slice_path);
|
||||
|
||||
cc::PaintFlags slice_flags;
|
||||
slice_flags.setStyle(cc::PaintFlags::kFill_Style);
|
||||
@ -317,6 +350,9 @@ void ProgressBar::MaybeNotifyAccessibilityValueChanged() {
|
||||
}
|
||||
|
||||
BEGIN_METADATA(ProgressBar, View)
|
||||
ADD_PROPERTY_METADATA(int, PreferredHeight)
|
||||
ADD_PROPERTY_METADATA(absl::optional<gfx::RoundedCornersF>,
|
||||
PreferredCornerRadii)
|
||||
ADD_PROPERTY_METADATA(SkColor, ForegroundColor, ui::metadata::SkColorConverter)
|
||||
ADD_PROPERTY_METADATA(SkColor, BackgroundColor, ui::metadata::SkColorConverter)
|
||||
ADD_PROPERTY_METADATA(absl::optional<ui::ColorId>, ForegroundColorId);
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
#include "ui/color/color_id.h"
|
||||
#include "ui/gfx/animation/animation_delegate.h"
|
||||
#include "ui/gfx/geometry/rounded_corners_f.h"
|
||||
#include "ui/views/view.h"
|
||||
|
||||
namespace gfx {
|
||||
@ -23,10 +24,7 @@ class VIEWS_EXPORT ProgressBar : public View, public gfx::AnimationDelegate {
|
||||
public:
|
||||
METADATA_HEADER(ProgressBar);
|
||||
|
||||
// The preferred height parameter makes it easier to use a ProgressBar with
|
||||
// layout managers that size to preferred size.
|
||||
explicit ProgressBar(int preferred_height = 5,
|
||||
bool allow_round_corner = true);
|
||||
ProgressBar();
|
||||
|
||||
ProgressBar(const ProgressBar&) = delete;
|
||||
ProgressBar& operator=(const ProgressBar&) = delete;
|
||||
@ -60,6 +58,19 @@ class VIEWS_EXPORT ProgressBar : public View, public gfx::AnimationDelegate {
|
||||
absl::optional<ui::ColorId> GetBackgroundColorId() const;
|
||||
void SetBackgroundColorId(absl::optional<ui::ColorId> color_id);
|
||||
|
||||
int GetPreferredHeight() const;
|
||||
void SetPreferredHeight(const int preferred_height);
|
||||
|
||||
// Calculates the rounded corners of the view based on
|
||||
// `preferred_corner_radii_`. If `preferred_corner_radii_` was not provided,
|
||||
// empty corners will be returned . If any corner radius in
|
||||
// `preferred_corner_radii_` is greater than the height of the bar, its value
|
||||
// will be capped to the height of the bar.
|
||||
gfx::RoundedCornersF GetPreferredCornerRadii() const;
|
||||
|
||||
void SetPreferredCornerRadii(
|
||||
const absl::optional<gfx::RoundedCornersF> preferred_corner_radii);
|
||||
|
||||
protected:
|
||||
int preferred_height() const { return preferred_height_; }
|
||||
|
||||
@ -81,10 +92,15 @@ class VIEWS_EXPORT ProgressBar : public View, public gfx::AnimationDelegate {
|
||||
// Is the progress bar paused.
|
||||
bool is_paused_ = false;
|
||||
|
||||
// In DP, the preferred height of this progress bar.
|
||||
const int preferred_height_;
|
||||
// In DP, the preferred height of this progress bar. This makes it easier to
|
||||
// use a ProgressBar with layout managers that size to preferred size.
|
||||
int preferred_height_ = 5;
|
||||
|
||||
const bool allow_round_corner_;
|
||||
// The radii to round the progress bar corners with. A value of
|
||||
// `absl::nullopt` will produce a bar with no rounded corners, otherwise a
|
||||
// default value of 3 on all corners will be used.
|
||||
absl::optional<gfx::RoundedCornersF> preferred_corner_radii_ =
|
||||
gfx::RoundedCornersF(3);
|
||||
|
||||
absl::optional<SkColor> foreground_color_;
|
||||
absl::optional<ui::ColorId> foreground_color_id_;
|
||||
|
@ -15,9 +15,10 @@
|
||||
#include "ui/events/test/event_generator.h"
|
||||
#include "ui/gfx/color_utils.h"
|
||||
#include "ui/native_theme/native_theme.h"
|
||||
#include "ui/views/layout/flex_layout.h"
|
||||
#include "ui/views/test/ax_event_counter.h"
|
||||
#include "ui/views/test/views_test_base.h"
|
||||
#include "ui/views/widget/widget_utils.h"
|
||||
#include "ui/views/test/views_test_utils.h"
|
||||
|
||||
namespace views {
|
||||
|
||||
@ -28,20 +29,27 @@ class ProgressBarTest : public ViewsTestBase {
|
||||
ViewsTestBase::SetUp();
|
||||
|
||||
widget_ = CreateTestWidget();
|
||||
widget_->SetContentsView(std::make_unique<ProgressBar>());
|
||||
container_view_ = widget_->SetContentsView(std::make_unique<View>());
|
||||
auto* layout =
|
||||
container_view_->SetLayoutManager(std::make_unique<FlexLayout>());
|
||||
layout->SetOrientation(views::LayoutOrientation::kVertical);
|
||||
bar_ = container_view_->AddChildView(std::make_unique<ProgressBar>());
|
||||
views::test::RunScheduledLayout(container_view_);
|
||||
widget_->Show();
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
container_view_ = nullptr;
|
||||
bar_ = nullptr;
|
||||
widget_.reset();
|
||||
ViewsTestBase::TearDown();
|
||||
}
|
||||
|
||||
ProgressBar* bar() {
|
||||
return static_cast<ProgressBar*>(widget_->GetContentsView());
|
||||
}
|
||||
ProgressBar* bar() { return bar_.get(); }
|
||||
|
||||
std::unique_ptr<Widget> widget_;
|
||||
raw_ptr<views::View> container_view_;
|
||||
raw_ptr<ProgressBar> bar_;
|
||||
};
|
||||
|
||||
TEST_F(ProgressBarTest, AccessibleNodeData) {
|
||||
@ -120,4 +128,40 @@ TEST_F(ProgressBarTest, OverrideDefaultColors) {
|
||||
EXPECT_EQ(absl::nullopt, bar()->GetBackgroundColorId());
|
||||
}
|
||||
|
||||
// Test that if no `preferred_corner_radii` are provided the default radius is
|
||||
// 3, and a value of `absl::nullopt` will not round the corners.
|
||||
TEST_F(ProgressBarTest, RoundCornerDefault) {
|
||||
// The default bar should have a rounded corner radius of 3.
|
||||
EXPECT_EQ(gfx::RoundedCornersF(3), bar()->GetPreferredCornerRadii());
|
||||
|
||||
// Setting `absl::nullopt` for the corner radius should make the bar have no
|
||||
// rounded corners.
|
||||
bar()->SetPreferredHeight(12);
|
||||
bar()->SetPreferredCornerRadii(absl::nullopt);
|
||||
views::test::RunScheduledLayout(container_view_);
|
||||
EXPECT_EQ(gfx::RoundedCornersF(0), bar()->GetPreferredCornerRadii());
|
||||
EXPECT_TRUE(bar()->GetPreferredCornerRadii().IsEmpty());
|
||||
}
|
||||
|
||||
// Test that a value set for `preferred_corner_radii` is saved and can be
|
||||
// retrieved from `GetPreferredCornerRadii()`.
|
||||
TEST_F(ProgressBarTest, RoundCornerRetrieval) {
|
||||
// Setting custom corners should result in them being saved.
|
||||
bar()->SetPreferredHeight(12);
|
||||
bar()->SetPreferredCornerRadii(gfx::RoundedCornersF(6));
|
||||
views::test::RunScheduledLayout(container_view_);
|
||||
EXPECT_EQ(gfx::RoundedCornersF(6), bar()->GetPreferredCornerRadii());
|
||||
}
|
||||
|
||||
// Test that `GetPreferredCornerRadii()` will return no corner with a radius
|
||||
// greater than the height of the bar.
|
||||
TEST_F(ProgressBarTest, RoundCornerMax) {
|
||||
// The max corner radius for a bar with a height of 12 should be 12.
|
||||
bar()->SetPreferredHeight(12);
|
||||
bar()->SetPreferredCornerRadii(gfx::RoundedCornersF(13, 14, 15, 16));
|
||||
views::test::RunScheduledLayout(container_view_);
|
||||
EXPECT_EQ(gfx::RoundedCornersF(12, 12, 12, 12),
|
||||
bar()->GetPreferredCornerRadii());
|
||||
}
|
||||
|
||||
} // namespace views
|
||||
|
@ -61,7 +61,9 @@ void ProgressBarExample::CreateExampleView(View* container) {
|
||||
|
||||
container->AddChildView(
|
||||
std::make_unique<Label>(GetStringUTF16(IDS_PROGRESS_LOADER_SHORT_LABEL)));
|
||||
container->AddChildView(std::make_unique<ProgressBar>(2))->SetValue(-1);
|
||||
auto* short_bar = container->AddChildView(std::make_unique<ProgressBar>());
|
||||
short_bar->SetValue(-1);
|
||||
short_bar->SetPreferredHeight(2);
|
||||
}
|
||||
|
||||
void ProgressBarExample::ButtonPressed(double step) {
|
||||
|
Reference in New Issue
Block a user