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

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

Issue 2696263002: Refactor ViewsDelegate and MD-ify the icon-to-text spacing for checkbox and radiobutton (Closed)
Patch Set: Reduced ViewsDelegate layout/metric functions to only two functions Created 3 years, 10 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/label_button.h" 5 #include "ui/views/controls/button/label_button.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 #include "ui/gfx/animation/throb_animation.h" 15 #include "ui/gfx/animation/throb_animation.h"
16 #include "ui/gfx/canvas.h" 16 #include "ui/gfx/canvas.h"
17 #include "ui/gfx/color_utils.h" 17 #include "ui/gfx/color_utils.h"
18 #include "ui/gfx/font_list.h" 18 #include "ui/gfx/font_list.h"
19 #include "ui/gfx/geometry/vector2d.h" 19 #include "ui/gfx/geometry/vector2d.h"
20 #include "ui/native_theme/native_theme.h" 20 #include "ui/native_theme/native_theme.h"
21 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" 21 #include "ui/views/animation/flood_fill_ink_drop_ripple.h"
22 #include "ui/views/animation/ink_drop.h" 22 #include "ui/views/animation/ink_drop.h"
23 #include "ui/views/animation/ink_drop_highlight.h" 23 #include "ui/views/animation/ink_drop_highlight.h"
24 #include "ui/views/animation/ink_drop_impl.h" 24 #include "ui/views/animation/ink_drop_impl.h"
25 #include "ui/views/animation/square_ink_drop_ripple.h" 25 #include "ui/views/animation/square_ink_drop_ripple.h"
26 #include "ui/views/background.h" 26 #include "ui/views/background.h"
27 #include "ui/views/controls/button/label_button_border.h" 27 #include "ui/views/controls/button/label_button_border.h"
28 #include "ui/views/painter.h" 28 #include "ui/views/painter.h"
29 #include "ui/views/style/platform_style.h" 29 #include "ui/views/style/platform_style.h"
30 #include "ui/views/views_delegate.h"
30 #include "ui/views/window/dialog_delegate.h" 31 #include "ui/views/window/dialog_delegate.h"
31 32
32 namespace { 33 namespace {
33 34
34 // The default spacing between the icon and text.
35 const int kSpacing = 5;
36
37 gfx::Font::Weight GetValueBolderThan(gfx::Font::Weight weight) { 35 gfx::Font::Weight GetValueBolderThan(gfx::Font::Weight weight) {
38 if (weight < gfx::Font::Weight::BOLD) 36 if (weight < gfx::Font::Weight::BOLD)
39 return gfx::Font::Weight::BOLD; 37 return gfx::Font::Weight::BOLD;
40 switch (weight) { 38 switch (weight) {
41 case gfx::Font::Weight::BOLD: 39 case gfx::Font::Weight::BOLD:
42 return gfx::Font::Weight::EXTRA_BOLD; 40 return gfx::Font::Weight::EXTRA_BOLD;
43 case gfx::Font::Weight::EXTRA_BOLD: 41 case gfx::Font::Weight::EXTRA_BOLD:
44 case gfx::Font::Weight::BLACK: 42 case gfx::Font::Weight::BLACK:
45 return gfx::Font::Weight::BLACK; 43 return gfx::Font::Weight::BLACK;
46 default: 44 default:
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 label_(new Label()), 84 label_(new Label()),
87 ink_drop_container_(new InkDropContainerView()), 85 ink_drop_container_(new InkDropContainerView()),
88 cached_normal_font_list_(GetDefaultNormalFontList()), 86 cached_normal_font_list_(GetDefaultNormalFontList()),
89 cached_bold_font_list_(GetDefaultBoldFontList()), 87 cached_bold_font_list_(GetDefaultBoldFontList()),
90 button_state_images_(), 88 button_state_images_(),
91 button_state_colors_(), 89 button_state_colors_(),
92 explicitly_set_colors_(), 90 explicitly_set_colors_(),
93 is_default_(false), 91 is_default_(false),
94 style_(STYLE_TEXTBUTTON), 92 style_(STYLE_TEXTBUTTON),
95 border_is_themed_border_(true), 93 border_is_themed_border_(true),
96 image_label_spacing_(kSpacing), 94 image_label_spacing_(ViewsDelegate::GetInstance()->GetSpacingMetric(
95 ViewsDelegate::SpacingMetric::ICON_TO_TEXT)),
97 horizontal_alignment_(gfx::ALIGN_LEFT) { 96 horizontal_alignment_(gfx::ALIGN_LEFT) {
98 SetAnimationDuration(kHoverAnimationDurationMs); 97 SetAnimationDuration(kHoverAnimationDurationMs);
99 SetTextInternal(text); 98 SetTextInternal(text);
100 99
101 AddChildView(ink_drop_container_); 100 AddChildView(ink_drop_container_);
102 ink_drop_container_->SetPaintToLayer(); 101 ink_drop_container_->SetPaintToLayer();
103 ink_drop_container_->layer()->SetFillsBoundsOpaquely(false); 102 ink_drop_container_->layer()->SetFillsBoundsOpaquely(false);
104 ink_drop_container_->SetVisible(false); 103 ink_drop_container_->SetVisible(false);
105 104
106 AddChildView(image_); 105 AddChildView(image_);
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 : PlatformStyle::TextColorForButton(button_state_colors_, *this); 603 : PlatformStyle::TextColorForButton(button_state_colors_, *this);
605 if (state() != STATE_DISABLED && label_->enabled_color() != color) 604 if (state() != STATE_DISABLED && label_->enabled_color() != color)
606 label_->SetEnabledColor(color); 605 label_->SetEnabledColor(color);
607 } 606 }
608 607
609 bool LabelButton::UseFloodFillInkDrop() const { 608 bool LabelButton::UseFloodFillInkDrop() const {
610 return !GetText().empty(); 609 return !GetText().empty();
611 } 610 }
612 611
613 } // namespace views 612 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698