0

Migrate views::ScrollView to ui::ColorVariant

Bug: b:394420459
Change-Id: I94ede48731d1c7c5f978c2e00ba0cc274e1dbe4e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6435440
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Reviewed-by: Elly FJ <ellyjones@chromium.org>
Commit-Queue: Zoraiz Naeem <zoraiznaeem@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1444493}
This commit is contained in:
Zoraiz Naeem
2025-04-08 18:34:23 -07:00
committed by Chromium LUCI CQ
parent 34904d59cb
commit 03f62ceebe
10 changed files with 30 additions and 56 deletions

@ -376,7 +376,7 @@ class MahiScrollView : public views::ScrollView,
explicit MahiScrollView(MahiUiController* ui_controller) explicit MahiScrollView(MahiUiController* ui_controller)
: MahiUiController::Delegate(ui_controller) { : MahiUiController::Delegate(ui_controller) {
SetEventTargeter(std::make_unique<views::ViewTargeter>(this)); SetEventTargeter(std::make_unique<views::ViewTargeter>(this));
SetBackgroundThemeColorId(cros_tokens::kCrosSysSystemOnBase); SetBackgroundColor(cros_tokens::kCrosSysSystemOnBase);
ClipHeightTo(/*min_height=*/0, /*max_height=*/INT_MAX); ClipHeightTo(/*min_height=*/0, /*max_height=*/INT_MAX);
SetDrawOverflowIndicator(false); SetDrawOverflowIndicator(false);
auto scroll_bar = std::make_unique<RoundedScrollBar>( auto scroll_bar = std::make_unique<RoundedScrollBar>(

@ -511,7 +511,7 @@ TabAppSelectionView::TabAppSelectionView(const base::Token& group_id,
// std::nullopt and apply a rounded rectangle background above on the whole // std::nullopt and apply a rounded rectangle background above on the whole
// view. We still need to set the viewport rounded corner radius to clip the // view. We still need to set the viewport rounded corner radius to clip the
// child backgrounds when they are hovered over. // child backgrounds when they are hovered over.
scroll_view_->SetBackgroundThemeColorId(std::nullopt); scroll_view_->SetBackgroundColor(std::nullopt);
scroll_view_->SetBorder(std::make_unique<views::HighlightBorder>( scroll_view_->SetBorder(std::make_unique<views::HighlightBorder>(
kTabAppItemsContainerCornerRadius, kTabAppItemsContainerCornerRadius,
views::HighlightBorder::Type::kHighlightBorderOnShadow)); views::HighlightBorder::Type::kHighlightBorderOnShadow));

@ -200,7 +200,7 @@ void RichAnswersView::SetUpBaseView() {
views::ScrollView* scroll_view = AddChildView( views::ScrollView* scroll_view = AddChildView(
views::Builder<views::ScrollView>() views::Builder<views::ScrollView>()
.ClipHeightTo(kMinimumRichCardHeight, kMaximumRichCardHeight) .ClipHeightTo(kMinimumRichCardHeight, kMaximumRichCardHeight)
.SetBackgroundThemeColorId(ui::kColorPrimaryBackground) .SetBackgroundColor(ui::kColorPrimaryBackground)
.SetHorizontalScrollBarMode( .SetHorizontalScrollBarMode(
views::ScrollView::ScrollBarMode::kDisabled) views::ScrollView::ScrollBarMode::kDisabled)
.SetDrawOverflowIndicator(false) .SetDrawOverflowIndicator(false)

@ -1081,7 +1081,7 @@ void PopupViewViews::CreateSuggestionViews() {
std::unique_ptr<views::ScrollView> scroll_view = std::unique_ptr<views::ScrollView> scroll_view =
views::Builder<views::ScrollView>() views::Builder<views::ScrollView>()
.SetBackgroundThemeColorId(ui::kColorDropdownBackground) .SetBackgroundColor(ui::kColorDropdownBackground)
.SetHorizontalScrollBarMode( .SetHorizontalScrollBarMode(
views::ScrollView::ScrollBarMode::kDisabled) views::ScrollView::ScrollBarMode::kDisabled)
.SetDrawOverflowIndicator(false) .SetDrawOverflowIndicator(false)

@ -280,7 +280,7 @@ bool ShouldSelectTab(DesktopMediaList::Type type,
std::unique_ptr<views::ScrollView> CreateScrollView(bool audio_requested) { std::unique_ptr<views::ScrollView> CreateScrollView(bool audio_requested) {
auto scroll_view = std::make_unique<views::ScrollView>(); auto scroll_view = std::make_unique<views::ScrollView>();
scroll_view->SetBackgroundThemeColorId(ui::kColorSysSurface4); scroll_view->SetBackgroundColor(ui::kColorSysSurface4);
// The overflow indicator is disabled to reduce clutter next to the // The overflow indicator is disabled to reduce clutter next to the
// separator to the audio control when audio is requested or the bottom of // separator to the audio control when audio is requested or the bottom of
// the dialog when audio is not requested. // the dialog when audio is not requested.

@ -57,7 +57,7 @@ std::unique_ptr<views::ScrollView> FileSystemAccessScrollPanel::Create(
// accessibility. // accessibility.
auto scroll_view = std::make_unique<views::ScrollView>(); auto scroll_view = std::make_unique<views::ScrollView>();
scroll_view->SetDrawOverflowIndicator(false); scroll_view->SetDrawOverflowIndicator(false);
scroll_view->SetBackgroundThemeColorId(ui::kColorSubtleEmphasisBackground); scroll_view->SetBackgroundColor(ui::kColorSubtleEmphasisBackground);
int line_container_height = int line_container_height =
file_list_container->children().empty() file_list_container->children().empty()
? 0 ? 0

@ -408,7 +408,7 @@ class IntentPickerAppListView
scrollable_view->AddChildViewAt(std::move(app_button), i); scrollable_view->AddChildViewAt(std::move(app_button), i);
} }
SetBackgroundThemeColorId(ui::kColorBubbleBackground); SetBackgroundColor(ui::kColorBubbleBackground);
SetContents(std::move(scrollable_view)); SetContents(std::move(scrollable_view));
DCHECK(!contents()->children().empty()); DCHECK(!contents()->children().empty());
const int row_height = const int row_height =

@ -105,7 +105,7 @@ void SharingHubBubbleViewImpl::Init() {
scroll_view_ = AddChildView(std::make_unique<views::ScrollView>()); scroll_view_ = AddChildView(std::make_unique<views::ScrollView>());
scroll_view_->ClipHeightTo(0, kActionButtonHeight * kMaximumButtons); scroll_view_->ClipHeightTo(0, kActionButtonHeight * kMaximumButtons);
scroll_view_->SetBackgroundThemeColorId(ui::kColorMenuBackground); scroll_view_->SetBackgroundColor(ui::kColorMenuBackground);
PopulateScrollView(controller_->GetFirstPartyActions()); PopulateScrollView(controller_->GetFirstPartyActions());
} }

@ -19,8 +19,8 @@
#include "ui/base/metadata/metadata_header_macros.h" #include "ui/base/metadata/metadata_header_macros.h"
#include "ui/base/metadata/metadata_impl_macros.h" #include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/base/ui_base_features.h" #include "ui/base/ui_base_features.h"
#include "ui/color/color_id.h"
#include "ui/color/color_provider.h" #include "ui/color/color_provider.h"
#include "ui/color/color_variant.h"
#include "ui/compositor/compositor.h" #include "ui/compositor/compositor.h"
#include "ui/compositor/layer.h" #include "ui/compositor/layer.h"
#include "ui/compositor/layer_type.h" #include "ui/compositor/layer_type.h"
@ -433,27 +433,16 @@ void ScrollView::SetViewportRoundedCornerRadius(
contents_viewport_->layer()->SetRoundedCornerRadius(radii); contents_viewport_->layer()->SetRoundedCornerRadius(radii);
} }
void ScrollView::SetBackgroundColor(const std::optional<SkColor>& color) { void ScrollView::SetBackgroundColor(
if (background_color_ == color && !background_color_id_) { const std::optional<ui::ColorVariant>& color) {
if (background_color_ == color) {
return; return;
} }
background_color_ = color; background_color_ = color;
background_color_id_ = std::nullopt;
UpdateBackground(); UpdateBackground();
OnPropertyChanged(&background_color_, kPropertyEffectsPaint); OnPropertyChanged(&background_color_, kPropertyEffectsPaint);
} }
void ScrollView::SetBackgroundThemeColorId(
const std::optional<ui::ColorId>& color_id) {
if (background_color_id_ == color_id && !background_color_) {
return;
}
background_color_id_ = color_id;
background_color_ = std::nullopt;
UpdateBackground();
OnPropertyChanged(&background_color_id_, kPropertyEffectsPaint);
}
gfx::Rect ScrollView::GetVisibleRect() const { gfx::Rect ScrollView::GetVisibleRect() const {
if (!contents_) { if (!contents_) {
return gfx::Rect(); return gfx::Rect();
@ -1294,10 +1283,9 @@ void ScrollView::UpdateBorder() {
return; return;
} }
SetBorder(CreateSolidBorder( SetBorder(CreateSolidBorder(1, draw_focus_indicator_
1, GetColorProvider()->GetColor( ? ui::kColorFocusableBorderFocused
draw_focus_indicator_ ? ui::kColorFocusableBorderFocused : ui::kColorFocusableBorderUnfocused));
: ui::kColorFocusableBorderUnfocused)));
} }
void ScrollView::UpdateBackground() { void ScrollView::UpdateBackground() {
@ -1305,7 +1293,7 @@ void ScrollView::UpdateBackground() {
return; return;
} }
const std::optional<SkColor> background_color = GetBackgroundColor(); const std::optional<ui::ColorVariant> background_color = GetBackgroundColor();
auto create_background = [background_color]() { auto create_background = [background_color]() {
return background_color ? CreateSolidBackground(background_color.value()) return background_color ? CreateSolidBackground(background_color.value())
@ -1330,14 +1318,8 @@ void ScrollView::UpdateBackground() {
} }
} }
std::optional<SkColor> ScrollView::GetBackgroundColor() const { std::optional<ui::ColorVariant> ScrollView::GetBackgroundColor() const {
return background_color_id_ return background_color_;
? GetColorProvider()->GetColor(background_color_id_.value())
: background_color_;
}
std::optional<ui::ColorId> ScrollView::GetBackgroundThemeColorId() const {
return background_color_id_;
} }
void ScrollView::PositionOverflowIndicators() { void ScrollView::PositionOverflowIndicators() {
@ -1388,8 +1370,7 @@ BEGIN_METADATA(ScrollView)
ADD_READONLY_PROPERTY_METADATA(int, MinHeight) ADD_READONLY_PROPERTY_METADATA(int, MinHeight)
ADD_READONLY_PROPERTY_METADATA(int, MaxHeight) ADD_READONLY_PROPERTY_METADATA(int, MaxHeight)
ADD_PROPERTY_METADATA(bool, AllowKeyboardScrolling) ADD_PROPERTY_METADATA(bool, AllowKeyboardScrolling)
ADD_PROPERTY_METADATA(std::optional<SkColor>, BackgroundColor) ADD_PROPERTY_METADATA(std::optional<ui::ColorVariant>, BackgroundColor)
ADD_PROPERTY_METADATA(std::optional<ui::ColorId>, BackgroundThemeColorId)
ADD_PROPERTY_METADATA(bool, DrawOverflowIndicator) ADD_PROPERTY_METADATA(bool, DrawOverflowIndicator)
ADD_PROPERTY_METADATA(bool, HasFocusIndicator) ADD_PROPERTY_METADATA(bool, HasFocusIndicator)
ADD_PROPERTY_METADATA(ScrollView::ScrollBarMode, HorizontalScrollBarMode) ADD_PROPERTY_METADATA(ScrollView::ScrollBarMode, HorizontalScrollBarMode)

@ -12,7 +12,7 @@
#include "base/callback_list.h" #include "base/callback_list.h"
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "base/memory/raw_ptr.h" #include "base/memory/raw_ptr.h"
#include "ui/color/color_id.h" #include "ui/color/color_variant.h"
#include "ui/compositor/layer_type.h" #include "ui/compositor/layer_type.h"
#include "ui/views/controls/focus_ring.h" #include "ui/views/controls/focus_ring.h"
#include "ui/views/controls/scrollbar/scroll_bar.h" #include "ui/views/controls/scrollbar/scroll_bar.h"
@ -127,18 +127,14 @@ class VIEWS_EXPORT ScrollView : public View, public ScrollBarController {
// rounded corners to the `contents_viewport_` layer. See `ScrollWithLayers`. // rounded corners to the `contents_viewport_` layer. See `ScrollWithLayers`.
void SetViewportRoundedCornerRadius(const gfx::RoundedCornersF& radii); void SetViewportRoundedCornerRadius(const gfx::RoundedCornersF& radii);
// The background color can be configured in two distinct ways: // Specify the background color:
// . By way of SetBackgroundThemeColorId(). This is the default and when // . Set a ColorId. This is the default and when called the background color
// called the background color comes from the theme (and changes if the // comes from the theme (and changes if the theme changes).
// theme changes). // . Set an explicit color.
// . By way of setting an explicit color, i.e. SetBackgroundColor(). Use // . Use std::nullopt if you don't want any color, but be warned this
// std::nullopt if you don't want any color, but be warned this
// produces awful results when layers are used with subpixel rendering. // produces awful results when layers are used with subpixel rendering.
std::optional<SkColor> GetBackgroundColor() const; std::optional<ui::ColorVariant> GetBackgroundColor() const;
void SetBackgroundColor(const std::optional<SkColor>& color); void SetBackgroundColor(const std::optional<ui::ColorVariant>& color);
std::optional<ui::ColorId> GetBackgroundThemeColorId() const;
void SetBackgroundThemeColorId(const std::optional<ui::ColorId>& color_id);
// Returns the visible region of the content View. // Returns the visible region of the content View.
gfx::Rect GetVisibleRect() const; gfx::Rect GetVisibleRect() const;
@ -153,8 +149,6 @@ class VIEWS_EXPORT ScrollView : public View, public ScrollBarController {
// |contents_| origin offset. // |contents_| origin offset.
gfx::PointF CurrentOffset() const; gfx::PointF CurrentOffset() const;
bool GetUseColorId() const { return !!background_color_id_; }
ScrollBarMode GetHorizontalScrollBarMode() const { ScrollBarMode GetHorizontalScrollBarMode() const {
return horizontal_scroll_bar_mode_; return horizontal_scroll_bar_mode_;
} }
@ -368,8 +362,8 @@ class VIEWS_EXPORT ScrollView : public View, public ScrollBarController {
int max_height_ = -1; int max_height_ = -1;
// See description of SetBackgroundColor() for details. // See description of SetBackgroundColor() for details.
std::optional<SkColor> background_color_; std::optional<ui::ColorVariant> background_color_ =
std::optional<ui::ColorId> background_color_id_ = ui::kColorDialogBackground; ui::kColorDialogBackground;
// How to handle the case when the contents overflow the viewport. // How to handle the case when the contents overflow the viewport.
ScrollBarMode horizontal_scroll_bar_mode_ = ScrollBarMode::kEnabled; ScrollBarMode horizontal_scroll_bar_mode_ = ScrollBarMode::kEnabled;
@ -416,13 +410,12 @@ VIEW_BUILDER_VIEW_TYPE_PROPERTY(View, Contents)
VIEW_BUILDER_PROPERTY(ui::LayerType, ContentsLayerType) VIEW_BUILDER_PROPERTY(ui::LayerType, ContentsLayerType)
VIEW_BUILDER_VIEW_TYPE_PROPERTY(View, Header) VIEW_BUILDER_VIEW_TYPE_PROPERTY(View, Header)
VIEW_BUILDER_PROPERTY(bool, AllowKeyboardScrolling) VIEW_BUILDER_PROPERTY(bool, AllowKeyboardScrolling)
VIEW_BUILDER_PROPERTY(std::optional<ui::ColorId>, BackgroundThemeColorId) VIEW_BUILDER_PROPERTY(std::optional<ui::ColorVariant>, BackgroundColor)
VIEW_BUILDER_METHOD(ClipHeightTo, int, int) VIEW_BUILDER_METHOD(ClipHeightTo, int, int)
VIEW_BUILDER_PROPERTY(ScrollView::ScrollBarMode, HorizontalScrollBarMode) VIEW_BUILDER_PROPERTY(ScrollView::ScrollBarMode, HorizontalScrollBarMode)
VIEW_BUILDER_PROPERTY(ScrollView::ScrollBarMode, VerticalScrollBarMode) VIEW_BUILDER_PROPERTY(ScrollView::ScrollBarMode, VerticalScrollBarMode)
VIEW_BUILDER_PROPERTY(bool, TreatAllScrollEventsAsHorizontal) VIEW_BUILDER_PROPERTY(bool, TreatAllScrollEventsAsHorizontal)
VIEW_BUILDER_PROPERTY(bool, DrawOverflowIndicator) VIEW_BUILDER_PROPERTY(bool, DrawOverflowIndicator)
VIEW_BUILDER_PROPERTY(std::optional<SkColor>, BackgroundColor)
VIEW_BUILDER_VIEW_PROPERTY(ScrollBar, HorizontalScrollBar) VIEW_BUILDER_VIEW_PROPERTY(ScrollBar, HorizontalScrollBar)
VIEW_BUILDER_VIEW_PROPERTY(ScrollBar, VerticalScrollBar) VIEW_BUILDER_VIEW_PROPERTY(ScrollBar, VerticalScrollBar)
VIEW_BUILDER_PROPERTY(bool, HasFocusIndicator) VIEW_BUILDER_PROPERTY(bool, HasFocusIndicator)