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