| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/ui/views/infobars/translate_infobar_base.h" | 5 #include "chrome/browser/ui/views/infobars/translate_infobar_base.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/translate/translate_infobar_delegate.h" | 8 #include "chrome/browser/translate/translate_infobar_delegate.h" |
| 9 #include "chrome/browser/ui/views/infobars/after_translate_infobar.h" | 9 #include "chrome/browser/ui/views/infobars/after_translate_infobar.h" |
| 10 #include "chrome/browser/ui/views/infobars/before_translate_infobar.h" | 10 #include "chrome/browser/ui/views/infobars/before_translate_infobar.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 } else if (animation == TranslateInfoBarDelegate::ERROR_TO_NORMAL) { | 65 } else if (animation == TranslateInfoBarDelegate::ERROR_TO_NORMAL) { |
| 66 // Hide() runs the animation in reverse. | 66 // Hide() runs the animation in reverse. |
| 67 background_color_animation_->Reset(1.0); | 67 background_color_animation_->Reset(1.0); |
| 68 background_color_animation_->Hide(); | 68 background_color_animation_->Hide(); |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 | 71 |
| 72 TranslateInfoBarBase::~TranslateInfoBarBase() { | 72 TranslateInfoBarBase::~TranslateInfoBarBase() { |
| 73 } | 73 } |
| 74 | 74 |
| 75 // static | |
| 76 views::Label* TranslateInfoBarBase::CreateLabel(const string16& text) { | |
| 77 views::Label* label = new views::Label(UTF16ToWideHack(text), | |
| 78 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont)); | |
| 79 label->SetColor(SK_ColorBLACK); | |
| 80 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | |
| 81 return label; | |
| 82 } | |
| 83 | |
| 84 // static | |
| 85 views::MenuButton* TranslateInfoBarBase::CreateMenuButton( | |
| 86 const string16& text, | |
| 87 bool normal_has_border, | |
| 88 views::ViewMenuDelegate* menu_delegate) { | |
| 89 // Don't use text to instantiate MenuButton because we need to set font before | |
| 90 // setting text so that the button will resize to fit the entire text. | |
| 91 views::MenuButton* menu_button = | |
| 92 new views::MenuButton(NULL, std::wstring(), menu_delegate, true); | |
| 93 menu_button->set_border(new InfoBarButtonBorder); | |
| 94 menu_button->set_menu_marker(ResourceBundle::GetSharedInstance(). | |
| 95 GetBitmapNamed(IDR_INFOBARBUTTON_MENU_DROPARROW)); | |
| 96 if (normal_has_border) { | |
| 97 menu_button->SetNormalHasBorder(true); // Normal button state has border. | |
| 98 // Disable animation during state change. | |
| 99 menu_button->SetAnimationDuration(0); | |
| 100 } | |
| 101 // Set font colors for different states. | |
| 102 menu_button->SetEnabledColor(SK_ColorBLACK); | |
| 103 menu_button->SetHighlightColor(SK_ColorBLACK); | |
| 104 menu_button->SetHoverColor(SK_ColorBLACK); | |
| 105 | |
| 106 // Set font then text, then size button to fit text. | |
| 107 menu_button->SetFont(ResourceBundle::GetSharedInstance().GetFont( | |
| 108 ResourceBundle::MediumFont)); | |
| 109 menu_button->SetText(UTF16ToWideHack(text)); | |
| 110 menu_button->ClearMaxTextSize(); | |
| 111 menu_button->SizeToPreferredSize(); | |
| 112 return menu_button; | |
| 113 } | |
| 114 | |
| 115 void TranslateInfoBarBase::Layout() { | 75 void TranslateInfoBarBase::Layout() { |
| 116 InfoBarView::Layout(); | 76 InfoBarView::Layout(); |
| 117 | 77 |
| 118 gfx::Size icon_size = icon_->GetPreferredSize(); | 78 gfx::Size icon_size = icon_->GetPreferredSize(); |
| 119 icon_->SetBounds(kHorizontalPadding, OffsetY(this, icon_size), | 79 icon_->SetBounds(kHorizontalPadding, OffsetY(this, icon_size), |
| 120 icon_size.width(), icon_size.height()); | 80 icon_size.width(), icon_size.height()); |
| 121 } | 81 } |
| 122 | 82 |
| 123 void TranslateInfoBarBase::UpdateLanguageButtonText( | 83 void TranslateInfoBarBase::UpdateLanguageButtonText( |
| 124 views::MenuButton* button, | 84 views::MenuButton* button, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 void TranslateInfoBarBase::FadeBackground(gfx::Canvas* canvas, | 124 void TranslateInfoBarBase::FadeBackground(gfx::Canvas* canvas, |
| 165 double animation_value, | 125 double animation_value, |
| 166 const views::Background& background) { | 126 const views::Background& background) { |
| 167 // Draw the background into an offscreen buffer with alpha value per animation | 127 // Draw the background into an offscreen buffer with alpha value per animation |
| 168 // value, then blend it back into the current canvas. | 128 // value, then blend it back into the current canvas. |
| 169 canvas->SaveLayerAlpha(static_cast<int>(animation_value * 255)); | 129 canvas->SaveLayerAlpha(static_cast<int>(animation_value * 255)); |
| 170 canvas->AsCanvasSkia()->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); | 130 canvas->AsCanvasSkia()->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); |
| 171 background.Paint(canvas, this); | 131 background.Paint(canvas, this); |
| 172 canvas->Restore(); | 132 canvas->Restore(); |
| 173 } | 133 } |
| OLD | NEW |