OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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/views/infobars/infobar_text_button.h" |
| 6 |
| 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" |
| 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/views/infobars/infobar_button_border.h" |
| 11 |
| 12 // static |
| 13 InfoBarTextButton* InfoBarTextButton::Create(views::ButtonListener* listener, |
| 14 const string16& text) { |
| 15 return new InfoBarTextButton(listener, text); |
| 16 } |
| 17 |
| 18 // static |
| 19 InfoBarTextButton* InfoBarTextButton::CreateWithMessageID( |
| 20 views::ButtonListener* listener, int message_id) { |
| 21 return new InfoBarTextButton(listener, |
| 22 l10n_util::GetStringUTF16(message_id)); |
| 23 } |
| 24 |
| 25 InfoBarTextButton::~InfoBarTextButton() { |
| 26 } |
| 27 |
| 28 bool InfoBarTextButton::OnMousePressed(const views::MouseEvent& e) { |
| 29 return views::CustomButton::OnMousePressed(e); |
| 30 } |
| 31 |
| 32 InfoBarTextButton::InfoBarTextButton(views::ButtonListener* listener, |
| 33 const string16& text) |
| 34 // Don't use text to construct TextButton because we need to set font |
| 35 // before setting text so that the button will resize to fit entire text. |
| 36 : TextButton(listener, std::wstring()) { |
| 37 set_border(new InfoBarButtonBorder); |
| 38 SetNormalHasBorder(true); // Normal button state has border. |
| 39 SetAnimationDuration(0); // Disable animation during state change. |
| 40 // Set font colors for different states. |
| 41 SetEnabledColor(SK_ColorBLACK); |
| 42 SetHighlightColor(SK_ColorBLACK); |
| 43 SetHoverColor(SK_ColorBLACK); |
| 44 // Set font then text, then size button to fit text. |
| 45 SetFont( |
| 46 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont)); |
| 47 SetText(UTF16ToWideHack(text)); |
| 48 ClearMaxTextSize(); |
| 49 SizeToPreferredSize(); |
| 50 } |
OLD | NEW |