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