| Index: ui/views/controls/button/vector_icon_image_updater.cc
|
| diff --git a/ui/views/controls/button/vector_icon_image_updater.cc b/ui/views/controls/button/vector_icon_image_updater.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..2c2207ed97ee86c55b34882783d3ef9fd826a535
|
| --- /dev/null
|
| +++ b/ui/views/controls/button/vector_icon_image_updater.cc
|
| @@ -0,0 +1,86 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "ui/views/controls/button/vector_icon_image_updater.h"
|
| +
|
| +#include "ui/gfx/color_utils.h"
|
| +#include "ui/gfx/paint_vector_icon.h"
|
| +#include "ui/views/animation/ink_drop_host_view.h"
|
| +#include "ui/views/controls/button/button.h"
|
| +#include "ui/views/controls/button/custom_button.h"
|
| +#include "ui/views/controls/button/image_button.h"
|
| +#include "ui/views/painter.h"
|
| +#include "ui/views/view.h"
|
| +#include "ui/views/views_delegate.h"
|
| +
|
| +namespace views {
|
| +
|
| +ImageButton* CreateImageButtonWithVectorIcon(const gfx::VectorIcon& icon,
|
| + ButtonListener* listener) {
|
| + return CreateImageButtonWithImageUpdater(new VectorIconImageUpdater(icon),
|
| + listener);
|
| +};
|
| +
|
| +ImageButton* CreateImageButtonWithImageUpdater(VectorIconImageUpdater* updater,
|
| + ButtonListener* listener) {
|
| + ImageButton* button = new ImageButton(listener);
|
| + updater->Attach(button);
|
| + button->SetInkDropMode(InkDropHostView::InkDropMode::ON);
|
| + button->set_has_ink_drop_action_on_click(true);
|
| + button->SetImageAlignment(ImageButton::ALIGN_CENTER,
|
| + ImageButton::ALIGN_MIDDLE);
|
| + button->SetFocusPainter(nullptr);
|
| + button->SetPadding(ViewsDelegate::GetInstance()->GetButtonMargins());
|
| + return button;
|
| +};
|
| +
|
| +VectorIconImageUpdater::VectorIconImageUpdater(const gfx::VectorIcon& icon)
|
| + : owner_button_(nullptr), icon_(&icon) {}
|
| +
|
| +void VectorIconImageUpdater::Attach(ImageButton* owner_button) {
|
| + DCHECK(owner_button);
|
| + owner_button_ = owner_button;
|
| + owner_button_->AddObserver(this);
|
| + UpdateButtonImages();
|
| +}
|
| +
|
| +void VectorIconImageUpdater::SetIcon(const gfx::VectorIcon& icon) {
|
| + icon_ = &icon;
|
| + UpdateButtonImages();
|
| +}
|
| +
|
| +void VectorIconImageUpdater::OnThemeChanged(View* observed_view) {
|
| + UpdateButtonImages();
|
| +}
|
| +
|
| +void VectorIconImageUpdater::OnNativeThemeChanged(
|
| + View* observed_view,
|
| + const ui::NativeTheme* theme) {
|
| + UpdateButtonImages();
|
| +}
|
| +
|
| +void VectorIconImageUpdater::OnViewIsDeleting(View* observed_view) {
|
| + delete this;
|
| +}
|
| +
|
| +void VectorIconImageUpdater::UpdateButtonImages() {
|
| + DCHECK(icon_);
|
| + if (!owner_button_)
|
| + return;
|
| +
|
| + SkColor icon_color =
|
| + color_utils::DeriveDefaultIconColor(GetVectorIconColor());
|
| + SkColor disabled_color = SkColorSetA(icon_color, 0xff / 2);
|
| + owner_button_->SetImage(CustomButton::STATE_NORMAL,
|
| + gfx::CreateVectorIcon(*icon_, icon_color));
|
| + owner_button_->SetImage(CustomButton::STATE_DISABLED,
|
| + gfx::CreateVectorIcon(*icon_, disabled_color));
|
| + owner_button_->set_ink_drop_base_color(icon_color);
|
| +}
|
| +
|
| +SkColor VectorIconImageUpdater::GetVectorIconColor() const {
|
| + return SK_ColorBLACK;
|
| +}
|
| +
|
| +} // namespace views
|
|
|