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

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

Issue 1773893002: Make MdTextButton a LabelButton, use it in the DL shelf. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove commented out code Created 4 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/label_button.h ('k') | ui/views/controls/button/md_text_button.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 (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
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 cached_bold_font_list_(GetDefaultBoldFontList()), 86 cached_bold_font_list_(GetDefaultBoldFontList()),
87 button_state_images_(), 87 button_state_images_(),
88 button_state_colors_(), 88 button_state_colors_(),
89 explicitly_set_colors_(), 89 explicitly_set_colors_(),
90 is_default_(false), 90 is_default_(false),
91 style_(STYLE_TEXTBUTTON), 91 style_(STYLE_TEXTBUTTON),
92 border_is_themed_border_(true), 92 border_is_themed_border_(true),
93 image_label_spacing_(kSpacing), 93 image_label_spacing_(kSpacing),
94 horizontal_alignment_(gfx::ALIGN_LEFT) { 94 horizontal_alignment_(gfx::ALIGN_LEFT) {
95 SetAnimationDuration(kHoverAnimationDurationMs); 95 SetAnimationDuration(kHoverAnimationDurationMs);
96 SetText(text); 96 SetTextInternal(text);
97 97
98 AddChildView(ink_drop_container_); 98 AddChildView(ink_drop_container_);
99 ink_drop_container_->SetPaintToLayer(true); 99 ink_drop_container_->SetPaintToLayer(true);
100 ink_drop_container_->SetFillsBoundsOpaquely(false); 100 ink_drop_container_->SetFillsBoundsOpaquely(false);
101 ink_drop_container_->SetVisible(false); 101 ink_drop_container_->SetVisible(false);
102 102
103 AddChildView(image_); 103 AddChildView(image_);
104 image_->set_interactive(false); 104 image_->set_interactive(false);
105 105
106 AddChildView(label_); 106 AddChildView(label_);
(...skipping 17 matching lines...) Expand all
124 void LabelButton::SetImage(ButtonState for_state, const gfx::ImageSkia& image) { 124 void LabelButton::SetImage(ButtonState for_state, const gfx::ImageSkia& image) {
125 button_state_images_[for_state] = image; 125 button_state_images_[for_state] = image;
126 UpdateImage(); 126 UpdateImage();
127 } 127 }
128 128
129 const base::string16& LabelButton::GetText() const { 129 const base::string16& LabelButton::GetText() const {
130 return label_->text(); 130 return label_->text();
131 } 131 }
132 132
133 void LabelButton::SetText(const base::string16& text) { 133 void LabelButton::SetText(const base::string16& text) {
134 SetAccessibleName(text); 134 SetTextInternal(text);
135 label_->SetText(text);
136 } 135 }
137 136
138 void LabelButton::SetTextColor(ButtonState for_state, SkColor color) { 137 void LabelButton::SetTextColor(ButtonState for_state, SkColor color) {
139 button_state_colors_[for_state] = color; 138 button_state_colors_[for_state] = color;
140 if (for_state == STATE_DISABLED) 139 if (for_state == STATE_DISABLED)
141 label_->SetDisabledColor(color); 140 label_->SetDisabledColor(color);
142 else if (for_state == state()) 141 else if (for_state == state())
143 label_->SetEnabledColor(color); 142 label_->SetEnabledColor(color);
144 explicitly_set_colors_[for_state] = true; 143 explicitly_set_colors_[for_state] = true;
145 } 144 }
(...skipping 13 matching lines...) Expand all
159 } 158 }
160 159
161 const gfx::FontList& LabelButton::GetFontList() const { 160 const gfx::FontList& LabelButton::GetFontList() const {
162 return label_->font_list(); 161 return label_->font_list();
163 } 162 }
164 163
165 void LabelButton::SetFontList(const gfx::FontList& font_list) { 164 void LabelButton::SetFontList(const gfx::FontList& font_list) {
166 cached_normal_font_list_ = font_list; 165 cached_normal_font_list_ = font_list;
167 cached_bold_font_list_ = font_list.DeriveWithStyle( 166 cached_bold_font_list_ = font_list.DeriveWithStyle(
168 font_list.GetFontStyle() | gfx::Font::BOLD); 167 font_list.GetFontStyle() | gfx::Font::BOLD);
169 168 label_->SetFontList(is_default_ ?
170 // STYLE_BUTTON uses bold text to indicate default buttons.
171 label_->SetFontList(
172 style_ == STYLE_BUTTON && is_default_ ?
173 cached_bold_font_list_ : cached_normal_font_list_); 169 cached_bold_font_list_ : cached_normal_font_list_);
174 } 170 }
175 171
176 void LabelButton::SetElideBehavior(gfx::ElideBehavior elide_behavior) { 172 void LabelButton::SetElideBehavior(gfx::ElideBehavior elide_behavior) {
177 label_->SetElideBehavior(elide_behavior); 173 label_->SetElideBehavior(elide_behavior);
178 } 174 }
179 175
180 void LabelButton::SetHorizontalAlignment(gfx::HorizontalAlignment alignment) { 176 void LabelButton::SetHorizontalAlignment(gfx::HorizontalAlignment alignment) {
181 DCHECK_NE(gfx::ALIGN_TO_HEAD, alignment); 177 DCHECK_NE(gfx::ALIGN_TO_HEAD, alignment);
182 horizontal_alignment_ = alignment; 178 horizontal_alignment_ = alignment;
183 InvalidateLayout(); 179 InvalidateLayout();
184 } 180 }
185 181
186 void LabelButton::SetMinSize(const gfx::Size& min_size) { 182 void LabelButton::SetMinSize(const gfx::Size& min_size) {
187 min_size_ = min_size; 183 min_size_ = min_size;
188 ResetCachedPreferredSize(); 184 ResetCachedPreferredSize();
189 } 185 }
190 186
191 void LabelButton::SetMaxSize(const gfx::Size& max_size) { 187 void LabelButton::SetMaxSize(const gfx::Size& max_size) {
192 max_size_ = max_size; 188 max_size_ = max_size;
193 ResetCachedPreferredSize(); 189 ResetCachedPreferredSize();
194 } 190 }
195 191
196 void LabelButton::SetIsDefault(bool is_default) { 192 void LabelButton::SetIsDefault(bool is_default) {
193 DCHECK_EQ(STYLE_BUTTON, style_);
197 if (is_default == is_default_) 194 if (is_default == is_default_)
198 return; 195 return;
196
199 is_default_ = is_default; 197 is_default_ = is_default;
200 ui::Accelerator accel(ui::VKEY_RETURN, ui::EF_NONE); 198 ui::Accelerator accel(ui::VKEY_RETURN, ui::EF_NONE);
201 is_default_ ? AddAccelerator(accel) : RemoveAccelerator(accel); 199 is_default_ ? AddAccelerator(accel) : RemoveAccelerator(accel);
202 200
203 // STYLE_BUTTON uses bold text to indicate default buttons. 201 label_->SetFontList(
204 if (style_ == STYLE_BUTTON) { 202 is_default ? cached_bold_font_list_ : cached_normal_font_list_);
205 label_->SetFontList( 203 InvalidateLayout();
206 is_default ? cached_bold_font_list_ : cached_normal_font_list_);
207 InvalidateLayout();
208 }
209 } 204 }
210 205
211 void LabelButton::SetStyle(ButtonStyle style) { 206 void LabelButton::SetStyle(ButtonStyle style) {
212 // All callers currently pass STYLE_BUTTON, and should only call this once, to 207 // All callers currently pass STYLE_BUTTON, and should only call this once, to
213 // change from the default style. 208 // change from the default style.
214 DCHECK_EQ(style, STYLE_BUTTON); 209 DCHECK_EQ(style, STYLE_BUTTON);
215 DCHECK_EQ(style_, STYLE_TEXTBUTTON); 210 DCHECK_EQ(style_, STYLE_TEXTBUTTON);
216 DCHECK(!GetWidget()) << "Can't change button style after adding to a Widget."; 211 DCHECK(!GetWidget()) << "Can't change button style after adding to a Widget.";
217 212
218 style_ = style; 213 style_ = style;
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 509
515 void LabelButton::UpdateThemedBorder() { 510 void LabelButton::UpdateThemedBorder() {
516 // Don't override borders set by others. 511 // Don't override borders set by others.
517 if (!border_is_themed_border_) 512 if (!border_is_themed_border_)
518 return; 513 return;
519 514
520 SetBorder(PlatformStyle::CreateThemedLabelButtonBorder(this)); 515 SetBorder(PlatformStyle::CreateThemedLabelButtonBorder(this));
521 border_is_themed_border_ = true; 516 border_is_themed_border_ = true;
522 } 517 }
523 518
519 void LabelButton::SetTextInternal(const base::string16& text) {
520 SetAccessibleName(text);
521 label_->SetText(text);
522 }
523
524 void LabelButton::ChildPreferredSizeChanged(View* child) { 524 void LabelButton::ChildPreferredSizeChanged(View* child) {
525 ResetCachedPreferredSize(); 525 ResetCachedPreferredSize();
526 PreferredSizeChanged(); 526 PreferredSizeChanged();
527 } 527 }
528 528
529 ui::NativeTheme::Part LabelButton::GetThemePart() const { 529 ui::NativeTheme::Part LabelButton::GetThemePart() const {
530 return ui::NativeTheme::kPushButton; 530 return ui::NativeTheme::kPushButton;
531 } 531 }
532 532
533 gfx::Rect LabelButton::GetThemePaintRect() const { 533 gfx::Rect LabelButton::GetThemePaintRect() const {
(...skipping 28 matching lines...) Expand all
562 GetExtraParams(params); 562 GetExtraParams(params);
563 return ui::NativeTheme::kHovered; 563 return ui::NativeTheme::kHovered;
564 } 564 }
565 565
566 void LabelButton::ResetCachedPreferredSize() { 566 void LabelButton::ResetCachedPreferredSize() {
567 cached_preferred_size_valid_ = false; 567 cached_preferred_size_valid_ = false;
568 cached_preferred_size_ = gfx::Size(); 568 cached_preferred_size_ = gfx::Size();
569 } 569 }
570 570
571 } // namespace views 571 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/label_button.h ('k') | ui/views/controls/button/md_text_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698