Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1001)

Side by Side Diff: ui/views/controls/button/vector_icon_button.cc

Issue 2305933002: Update dialog close buttons to use vector icons and ripples. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/bar_control_button.h" 5 #include "ui/views/controls/button/vector_icon_button.h"
6 6
7 #include "ui/base/material_design/material_design_controller.h" 7 #include "ui/base/material_design/material_design_controller.h"
8 #include "ui/gfx/color_palette.h"
8 #include "ui/gfx/color_utils.h" 9 #include "ui/gfx/color_utils.h"
9 #include "ui/gfx/paint_vector_icon.h" 10 #include "ui/gfx/paint_vector_icon.h"
10 #include "ui/gfx/vector_icons_public.h" 11 #include "ui/gfx/vector_icons_public.h"
11 #include "ui/views/border.h" 12 #include "ui/views/border.h"
12 #include "ui/views/painter.h" 13 #include "ui/views/painter.h"
13 14
15 namespace views {
16
14 namespace { 17 namespace {
15 18
16 // Extra space around the buttons to increase their event target size. 19 // Extra space around the buttons to increase their event target size.
17 const int kButtonExtraTouchSize = 4; 20 const int kButtonExtraTouchSize = 4;
18 21
19 } // namespace 22 } // namespace
20 23
21 BarControlButton::BarControlButton(views::ButtonListener* listener) 24 VectorIconButton::VectorIconButton(views::ButtonListener* listener)
22 : views::ImageButton(listener), id_(gfx::VectorIconId::VECTOR_ICON_NONE) { 25 : views::ImageButton(listener), id_(gfx::VectorIconId::VECTOR_ICON_NONE) {
23 if (ui::MaterialDesignController::IsModeMaterial()) 26 if (ui::MaterialDesignController::IsModeMaterial())
24 SetInkDropMode(InkDropMode::ON); 27 SetInkDropMode(InkDropMode::ON);
25 set_has_ink_drop_action_on_click(true); 28 set_has_ink_drop_action_on_click(true);
26 SetImageAlignment(views::ImageButton::ALIGN_CENTER, 29 SetImageAlignment(views::ImageButton::ALIGN_CENTER,
27 views::ImageButton::ALIGN_MIDDLE); 30 views::ImageButton::ALIGN_MIDDLE);
28 SetFocusPainter(nullptr); 31 SetFocusPainter(nullptr);
29 } 32 }
30 33
31 BarControlButton::~BarControlButton() {} 34 VectorIconButton::~VectorIconButton() {}
32 35
33 void BarControlButton::SetIcon( 36 void VectorIconButton::SetIcon(
34 gfx::VectorIconId id, 37 gfx::VectorIconId id,
35 const base::Callback<SkColor(void)>& get_text_color_callback) { 38 const base::Callback<SkColor(void)>& get_text_color_callback) {
36 id_ = id; 39 id_ = id;
37 get_text_color_callback_ = get_text_color_callback; 40 get_text_color_callback_ = get_text_color_callback;
38 41
39 if (!border()) { 42 if (!border()) {
40 SetBorder(views::Border::CreateEmptyBorder( 43 SetBorder(views::Border::CreateEmptyBorder(
41 kButtonExtraTouchSize, kButtonExtraTouchSize, kButtonExtraTouchSize, 44 kButtonExtraTouchSize, kButtonExtraTouchSize, kButtonExtraTouchSize,
42 kButtonExtraTouchSize)); 45 kButtonExtraTouchSize));
43 } 46 }
44 } 47 }
45 48
46 void BarControlButton::OnThemeChanged() { 49 void VectorIconButton::OnEnabledChanged() {
50 OnThemeChanged();
51 }
52
53 void VectorIconButton::OnThemeChanged() {
47 SkColor icon_color = 54 SkColor icon_color =
55 get_text_color_callback_.is_null() ? gfx::kChromeIconGrey :
48 color_utils::DeriveDefaultIconColor(get_text_color_callback_.Run()); 56 color_utils::DeriveDefaultIconColor(get_text_color_callback_.Run());
49 gfx::ImageSkia image = gfx::CreateVectorIcon(id_, icon_color); 57 gfx::ImageSkia image = gfx::CreateVectorIcon(id_, icon_color);
50 SetImage(views::CustomButton::STATE_NORMAL, &image); 58 SetImage(views::CustomButton::STATE_NORMAL, &image);
51 image = gfx::CreateVectorIcon(id_, SkColorSetA(icon_color, 0xff / 2)); 59 image = gfx::CreateVectorIcon(id_, SkColorSetA(icon_color, 0xff / 2));
52 SetImage(views::CustomButton::STATE_DISABLED, &image); 60 SetImage(views::CustomButton::STATE_DISABLED, &image);
53 set_ink_drop_base_color(icon_color); 61 set_ink_drop_base_color(icon_color);
54 } 62 }
55 63
56 void BarControlButton::OnNativeThemeChanged(const ui::NativeTheme* theme) { 64 void VectorIconButton::OnNativeThemeChanged(const ui::NativeTheme* theme) {
57 OnThemeChanged(); 65 OnThemeChanged();
58 } 66 }
67
68 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698