| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/views/bar_control_button.h" | |
| 6 | |
| 7 #include "ui/base/material_design/material_design_controller.h" | |
| 8 #include "ui/gfx/color_utils.h" | |
| 9 #include "ui/gfx/paint_vector_icon.h" | |
| 10 #include "ui/gfx/vector_icons_public.h" | |
| 11 #include "ui/views/border.h" | |
| 12 #include "ui/views/painter.h" | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 // Extra space around the buttons to increase their event target size. | |
| 17 const int kButtonExtraTouchSize = 4; | |
| 18 | |
| 19 } // namespace | |
| 20 | |
| 21 BarControlButton::BarControlButton(views::ButtonListener* listener) | |
| 22 : views::ImageButton(listener), id_(gfx::VectorIconId::VECTOR_ICON_NONE) { | |
| 23 if (ui::MaterialDesignController::IsModeMaterial()) | |
| 24 SetInkDropMode(InkDropMode::ON); | |
| 25 set_has_ink_drop_action_on_click(true); | |
| 26 SetImageAlignment(views::ImageButton::ALIGN_CENTER, | |
| 27 views::ImageButton::ALIGN_MIDDLE); | |
| 28 SetFocusPainter(nullptr); | |
| 29 } | |
| 30 | |
| 31 BarControlButton::~BarControlButton() {} | |
| 32 | |
| 33 void BarControlButton::SetIcon( | |
| 34 gfx::VectorIconId id, | |
| 35 const base::Callback<SkColor(void)>& get_text_color_callback) { | |
| 36 id_ = id; | |
| 37 get_text_color_callback_ = get_text_color_callback; | |
| 38 | |
| 39 if (!border()) { | |
| 40 SetBorder(views::Border::CreateEmptyBorder( | |
| 41 kButtonExtraTouchSize, kButtonExtraTouchSize, kButtonExtraTouchSize, | |
| 42 kButtonExtraTouchSize)); | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 void BarControlButton::OnThemeChanged() { | |
| 47 SkColor icon_color = | |
| 48 color_utils::DeriveDefaultIconColor(get_text_color_callback_.Run()); | |
| 49 gfx::ImageSkia image = gfx::CreateVectorIcon(id_, icon_color); | |
| 50 SetImage(views::CustomButton::STATE_NORMAL, &image); | |
| 51 image = gfx::CreateVectorIcon(id_, SkColorSetA(icon_color, 0xff / 2)); | |
| 52 SetImage(views::CustomButton::STATE_DISABLED, &image); | |
| 53 set_ink_drop_base_color(icon_color); | |
| 54 } | |
| 55 | |
| 56 void BarControlButton::OnNativeThemeChanged(const ui::NativeTheme* theme) { | |
| 57 OnThemeChanged(); | |
| 58 } | |
| OLD | NEW |