Commit 1a469e2b authored by minch's avatar minch Committed by Commit Bot

dark_mode: Update slider icon.

Make UnifiedSliderButton as ImageButton only and decorate it with
kIconButtonSmallOrMedium.

Bug: 1133748
Change-Id: Ic154c6ef63770d66ae4d09eb4b3cf1190be056cf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2441190
Commit-Queue: Min Chen <minch@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#813032}
parent 02f29ab6
......@@ -74,7 +74,7 @@ void ReadOnlySlider::OnGestureEvent(ui::GestureEvent* event) {}
UnifiedSliderButton::UnifiedSliderButton(views::ButtonListener* listener,
const gfx::VectorIcon& icon,
int accessible_name_id)
: views::ToggleImageButton(listener) {
: views::ImageButton(listener) {
SetImageHorizontalAlignment(ALIGN_CENTER);
SetImageVerticalAlignment(ALIGN_MIDDLE);
if (accessible_name_id)
......@@ -105,24 +105,13 @@ const char* UnifiedSliderButton::GetClassName() const {
}
void UnifiedSliderButton::SetVectorIcon(const gfx::VectorIcon& icon) {
const SkColor toggled_color = AshColorProvider::Get()->GetContentLayerColor(
ContentLayerType::kButtonIconColorPrimary);
const SkColor icon_color = AshColorProvider::Get()->GetContentLayerColor(
ContentLayerType::kButtonIconColor);
SetImage(views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(icon, icon_color));
toggled_icon_ = gfx::CreateVectorIcon(icon, toggled_color);
SetToggledImage(views::Button::STATE_NORMAL, &toggled_icon_);
SetImage(views::Button::STATE_DISABLED,
gfx::CreateVectorIcon(icon, icon_color));
icon_ = &icon;
UpdateVectorIcon();
}
void UnifiedSliderButton::SetToggled(bool toggled) {
toggled_ = toggled;
views::ToggleImageButton::SetToggled(toggled);
UpdateVectorIcon();
}
void UnifiedSliderButton::PaintButtonContents(gfx::Canvas* canvas) {
......@@ -160,12 +149,21 @@ UnifiedSliderButton::CreateInkDropHighlight() const {
void UnifiedSliderButton::GetAccessibleNodeData(ui::AXNodeData* node_data) {
if (!GetEnabled())
return;
views::ToggleImageButton::GetAccessibleNodeData(node_data);
views::ImageButton::GetAccessibleNodeData(node_data);
node_data->role = ax::mojom::Role::kToggleButton;
node_data->SetCheckedState(toggled_ ? ax::mojom::CheckedState::kTrue
: ax::mojom::CheckedState::kFalse);
}
void UnifiedSliderButton::UpdateVectorIcon() {
if (!icon_)
return;
AshColorProvider::Get()->DecorateIconButton(
this, AshColorProvider::ButtonType::kIconButtonSmallOrMedium, *icon_,
toggled_, GetDefaultSizeOfVectorIcon(*icon_));
}
UnifiedSliderView::UnifiedSliderView(UnifiedSliderListener* listener,
const gfx::VectorIcon& icon,
int accessible_name_id,
......
......@@ -54,7 +54,7 @@ class ReadOnlySlider : public SystemSlider {
};
// A button used in a slider row of UnifiedSystemTray. The button is togglable.
class UnifiedSliderButton : public views::ToggleImageButton {
class UnifiedSliderButton : public views::ImageButton {
public:
UnifiedSliderButton(views::ButtonListener* listener,
const gfx::VectorIcon& icon,
......@@ -73,7 +73,7 @@ class UnifiedSliderButton : public views::ToggleImageButton {
// views::Button:
const char* GetClassName() const override;
// views::ToggleImageButton:
// views::ImageButton:
std::unique_ptr<views::InkDrop> CreateInkDrop() override;
std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override;
std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
......@@ -83,11 +83,12 @@ class UnifiedSliderButton : public views::ToggleImageButton {
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
private:
void UpdateVectorIcon();
// True if the button is currently toggled.
bool toggled_ = false;
// Icon used when the button is toggled.
gfx::ImageSkia toggled_icon_;
const gfx::VectorIcon* icon_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(UnifiedSliderButton);
};
......
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