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

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

Issue 2671443002: Make the extra padding around VectorIconButtons configurable. (Closed)
Patch Set: Resync Created 3 years, 9 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
« no previous file with comments | « ui/views/controls/button/vector_icon_button.h ('k') | ui/views/layout/layout_constants.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ui/views/controls/button/vector_icon_button.h" 5 #include "ui/views/controls/button/vector_icon_button.h"
6 6
7 #include "ui/gfx/color_palette.h" 7 #include "ui/gfx/color_palette.h"
8 #include "ui/gfx/color_utils.h" 8 #include "ui/gfx/color_utils.h"
9 #include "ui/gfx/paint_vector_icon.h" 9 #include "ui/gfx/paint_vector_icon.h"
10 #include "ui/gfx/vector_icons_public.h" 10 #include "ui/gfx/vector_icons_public.h"
11 #include "ui/views/animation/ink_drop_highlight.h"
12 #include "ui/views/animation/ink_drop_ripple.h"
11 #include "ui/views/border.h" 13 #include "ui/views/border.h"
12 #include "ui/views/controls/button/vector_icon_button_delegate.h" 14 #include "ui/views/controls/button/vector_icon_button_delegate.h"
13 #include "ui/views/painter.h" 15 #include "ui/views/painter.h"
16 #include "ui/views/views_delegate.h"
14 17
15 namespace views { 18 namespace views {
16 19
17 namespace {
18
19 // Extra space around the buttons to increase their event target size.
20 const int kButtonExtraTouchSize = 4;
21
22 } // namespace
23
24 VectorIconButton::VectorIconButton(VectorIconButtonDelegate* delegate) 20 VectorIconButton::VectorIconButton(VectorIconButtonDelegate* delegate)
25 : ImageButton(delegate), 21 : ImageButton(delegate),
26 delegate_(delegate), 22 delegate_(delegate),
27 id_(gfx::VectorIconId::VECTOR_ICON_NONE) { 23 id_(gfx::VectorIconId::VECTOR_ICON_NONE) {
28 SetInkDropMode(InkDropMode::ON); 24 SetInkDropMode(InkDropMode::ON);
29 set_has_ink_drop_action_on_click(true); 25 set_has_ink_drop_action_on_click(true);
30 SetImageAlignment(ImageButton::ALIGN_CENTER, ImageButton::ALIGN_MIDDLE); 26 SetImageAlignment(ImageButton::ALIGN_CENTER, ImageButton::ALIGN_MIDDLE);
31 SetFocusPainter(nullptr); 27 SetFocusPainter(nullptr);
32 } 28 }
33 29
(...skipping 14 matching lines...) Expand all
48 } 44 }
49 45
50 void VectorIconButton::OnThemeChanged() { 46 void VectorIconButton::OnThemeChanged() {
51 UpdateImagesAndColors(); 47 UpdateImagesAndColors();
52 } 48 }
53 49
54 void VectorIconButton::OnNativeThemeChanged(const ui::NativeTheme* theme) { 50 void VectorIconButton::OnNativeThemeChanged(const ui::NativeTheme* theme) {
55 UpdateImagesAndColors(); 51 UpdateImagesAndColors();
56 } 52 }
57 53
54 std::unique_ptr<InkDropRipple> VectorIconButton::CreateInkDropRipple() const {
55 return CreateDefaultInkDropRipple(GetLocalBounds().CenterPoint(), size());
56 }
57
58 std::unique_ptr<InkDropHighlight> VectorIconButton::CreateInkDropHighlight()
59 const {
60 return CreateDefaultInkDropHighlight(
61 gfx::RectF(GetLocalBounds()).CenterPoint(), size());
62 }
63
58 void VectorIconButton::OnSetIcon() { 64 void VectorIconButton::OnSetIcon() {
59 if (!border()) 65 const gfx::Insets insets = ViewsDelegate::GetInstance()->GetButtonMargins();
60 SetBorder(CreateEmptyBorder(gfx::Insets(kButtonExtraTouchSize))); 66 if (!border() && !insets.IsEmpty())
67 SetBorder(CreateEmptyBorder(insets));
61 68
62 UpdateImagesAndColors(); 69 UpdateImagesAndColors();
63 } 70 }
64 71
65 void VectorIconButton::UpdateImagesAndColors() { 72 void VectorIconButton::UpdateImagesAndColors() {
66 SkColor icon_color = 73 SkColor icon_color =
67 color_utils::DeriveDefaultIconColor(delegate_->GetVectorIconBaseColor()); 74 color_utils::DeriveDefaultIconColor(delegate_->GetVectorIconBaseColor());
68 SkColor disabled_color = SkColorSetA(icon_color, 0xff / 2); 75 SkColor disabled_color = SkColorSetA(icon_color, 0xff / 2);
69 if (icon_) { 76 if (icon_) {
70 SetImage(CustomButton::STATE_NORMAL, 77 SetImage(CustomButton::STATE_NORMAL,
71 gfx::CreateVectorIcon(*icon_, icon_color)); 78 gfx::CreateVectorIcon(*icon_, icon_color));
72 SetImage(CustomButton::STATE_DISABLED, 79 SetImage(CustomButton::STATE_DISABLED,
73 gfx::CreateVectorIcon(*icon_, disabled_color)); 80 gfx::CreateVectorIcon(*icon_, disabled_color));
74 } else { 81 } else {
75 SetImage(CustomButton::STATE_NORMAL, 82 SetImage(CustomButton::STATE_NORMAL,
76 gfx::CreateVectorIcon(id_, icon_color)); 83 gfx::CreateVectorIcon(id_, icon_color));
77 SetImage(CustomButton::STATE_DISABLED, 84 SetImage(CustomButton::STATE_DISABLED,
78 gfx::CreateVectorIcon(id_, disabled_color)); 85 gfx::CreateVectorIcon(id_, disabled_color));
79 } 86 }
80 set_ink_drop_base_color(icon_color); 87 set_ink_drop_base_color(icon_color);
81 } 88 }
82 89
83 } // namespace views 90 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/vector_icon_button.h ('k') | ui/views/layout/layout_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698