| OLD | NEW |
| 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 "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/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/infobars/infobar.h" | |
| 9 #include "chrome/browser/translate/translate_infobar_delegate.h" | 8 #include "chrome/browser/translate/translate_infobar_delegate.h" |
| 10 #include "chrome/browser/ui/views/infobars/after_translate_infobar.h" | 9 #include "chrome/browser/ui/views/infobars/after_translate_infobar.h" |
| 11 #include "chrome/browser/ui/views/infobars/before_translate_infobar.h" | 10 #include "chrome/browser/ui/views/infobars/before_translate_infobar.h" |
| 12 #include "chrome/browser/ui/views/infobars/translate_message_infobar.h" | 11 #include "chrome/browser/ui/views/infobars/translate_message_infobar.h" |
| 13 #include "grit/theme_resources.h" | 12 #include "grit/theme_resources.h" |
| 14 #include "ui/base/resource/resource_bundle.h" | 13 #include "ui/base/resource/resource_bundle.h" |
| 15 #include "ui/gfx/animation/slide_animation.h" | 14 #include "ui/gfx/animation/slide_animation.h" |
| 16 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
| 17 #include "ui/views/controls/button/menu_button.h" | 16 #include "ui/views/controls/button/menu_button.h" |
| 18 #include "ui/views/controls/label.h" | 17 #include "ui/views/controls/label.h" |
| 19 | 18 |
| 20 | 19 |
| 21 // TranslateInfoBarDelegate --------------------------------------------------- | 20 // TranslateInfoBarDelegate --------------------------------------------------- |
| 22 | 21 |
| 23 // static | 22 InfoBar* TranslateInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { |
| 24 scoped_ptr<InfoBar> TranslateInfoBarDelegate::CreateInfoBar( | 23 if (infobar_type_ == BEFORE_TRANSLATE) |
| 25 scoped_ptr<TranslateInfoBarDelegate> delegate) { | 24 return new BeforeTranslateInfoBar(owner, this); |
| 26 if (delegate->infobar_type() == BEFORE_TRANSLATE) | 25 if (infobar_type_ == AFTER_TRANSLATE) |
| 27 return scoped_ptr<InfoBar>(new BeforeTranslateInfoBar(delegate.Pass())); | 26 return new AfterTranslateInfoBar(owner, this); |
| 28 if (delegate->infobar_type() == AFTER_TRANSLATE) | 27 return new TranslateMessageInfoBar(owner, this); |
| 29 return scoped_ptr<InfoBar>(new AfterTranslateInfoBar(delegate.Pass())); | |
| 30 return scoped_ptr<InfoBar>(new TranslateMessageInfoBar(delegate.Pass())); | |
| 31 } | 28 } |
| 32 | 29 |
| 33 | 30 |
| 34 // TranslateInfoBarBase ------------------------------------------------------- | 31 // TranslateInfoBarBase ------------------------------------------------------- |
| 35 | 32 |
| 36 // static | 33 // static |
| 37 const int TranslateInfoBarBase::kButtonInLabelSpacing = 5; | 34 const int TranslateInfoBarBase::kButtonInLabelSpacing = 5; |
| 38 | 35 |
| 39 void TranslateInfoBarBase::UpdateLanguageButtonText(views::MenuButton* button, | 36 void TranslateInfoBarBase::UpdateLanguageButtonText(views::MenuButton* button, |
| 40 const string16& text) { | 37 const string16& text) { |
| 41 DCHECK(button); | 38 DCHECK(button); |
| 42 button->SetText(text); | 39 button->SetText(text); |
| 43 // The button may have to grow to show the new text. | 40 // The button may have to grow to show the new text. |
| 44 Layout(); | 41 Layout(); |
| 45 SchedulePaint(); | 42 SchedulePaint(); |
| 46 } | 43 } |
| 47 | 44 |
| 48 TranslateInfoBarBase::TranslateInfoBarBase( | 45 TranslateInfoBarBase::TranslateInfoBarBase(InfoBarService* owner, |
| 49 scoped_ptr<TranslateInfoBarDelegate> delegate) | 46 TranslateInfoBarDelegate* delegate) |
| 50 : InfoBarView(delegate.PassAs<InfoBarDelegate>()), | 47 : InfoBarView(owner, delegate), |
| 51 error_background_(InfoBarDelegate::WARNING_TYPE) { | 48 error_background_(InfoBarDelegate::WARNING_TYPE) { |
| 52 } | 49 } |
| 53 | 50 |
| 54 TranslateInfoBarBase::~TranslateInfoBarBase() { | 51 TranslateInfoBarBase::~TranslateInfoBarBase() { |
| 55 } | 52 } |
| 56 | 53 |
| 57 void TranslateInfoBarBase::ViewHierarchyChanged( | 54 void TranslateInfoBarBase::ViewHierarchyChanged( |
| 58 const ViewHierarchyChangedDetails& details) { | 55 const ViewHierarchyChangedDetails& details) { |
| 59 if (details.is_add && (details.child == this) && | 56 if (details.is_add && (details.child == this) && |
| 60 (background_color_animation_ == NULL)) { | 57 (background_color_animation_ == NULL)) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 111 |
| 115 void TranslateInfoBarBase::FadeBackground(gfx::Canvas* canvas, | 112 void TranslateInfoBarBase::FadeBackground(gfx::Canvas* canvas, |
| 116 double animation_value, | 113 double animation_value, |
| 117 const views::Background& background) { | 114 const views::Background& background) { |
| 118 // Draw the background into an offscreen buffer with alpha value per animation | 115 // Draw the background into an offscreen buffer with alpha value per animation |
| 119 // value, then blend it back into the current canvas. | 116 // value, then blend it back into the current canvas. |
| 120 canvas->SaveLayerAlpha(static_cast<int>(animation_value * 255)); | 117 canvas->SaveLayerAlpha(static_cast<int>(animation_value * 255)); |
| 121 background.Paint(canvas, this); | 118 background.Paint(canvas, this); |
| 122 canvas->Restore(); | 119 canvas->Restore(); |
| 123 } | 120 } |
| OLD | NEW |