This source file includes following definitions.
- CreateInfoBar
- UpdateLanguageButtonText
- error_background_
- ViewHierarchyChanged
- GetDelegate
- OnPaintBackground
- AnimationProgressed
- GetBackground
- FadeBackground
#include "chrome/browser/ui/views/infobars/translate_infobar_base.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/infobars/infobar.h"
#include "chrome/browser/translate/translate_infobar_delegate.h"
#include "chrome/browser/translate/translate_tab_helper.h"
#include "chrome/browser/ui/views/infobars/after_translate_infobar.h"
#include "chrome/browser/ui/views/infobars/before_translate_infobar.h"
#include "chrome/browser/ui/views/infobars/translate_message_infobar.h"
#include "grit/theme_resources.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/animation/slide_animation.h"
#include "ui/gfx/canvas.h"
#include "ui/views/controls/button/menu_button.h"
#include "ui/views/controls/label.h"
scoped_ptr<InfoBar> TranslateInfoBarDelegate::CreateInfoBar(
scoped_ptr<TranslateInfoBarDelegate> delegate) {
if (delegate->translate_step() == TranslateTabHelper::BEFORE_TRANSLATE)
return scoped_ptr<InfoBar>(new BeforeTranslateInfoBar(delegate.Pass()));
if (delegate->translate_step() == TranslateTabHelper::AFTER_TRANSLATE)
return scoped_ptr<InfoBar>(new AfterTranslateInfoBar(delegate.Pass()));
return scoped_ptr<InfoBar>(new TranslateMessageInfoBar(delegate.Pass()));
}
const int TranslateInfoBarBase::kButtonInLabelSpacing = 5;
void TranslateInfoBarBase::UpdateLanguageButtonText(
views::MenuButton* button,
const base::string16& text) {
DCHECK(button);
button->SetText(text);
button->ClearMaxTextSize();
button->SizeToPreferredSize();
Layout();
SchedulePaint();
}
TranslateInfoBarBase::TranslateInfoBarBase(
scoped_ptr<TranslateInfoBarDelegate> delegate)
: InfoBarView(delegate.PassAs<InfoBarDelegate>()),
error_background_(InfoBarDelegate::WARNING_TYPE) {
}
TranslateInfoBarBase::~TranslateInfoBarBase() {
}
void TranslateInfoBarBase::ViewHierarchyChanged(
const ViewHierarchyChangedDetails& details) {
if (details.is_add && (details.child == this) &&
(background_color_animation_ == NULL)) {
background_color_animation_.reset(new gfx::SlideAnimation(this));
background_color_animation_->SetTweenType(gfx::Tween::LINEAR);
background_color_animation_->SetSlideDuration(500);
TranslateInfoBarDelegate::BackgroundAnimationType animation =
GetDelegate()->background_animation_type();
if (animation == TranslateInfoBarDelegate::NORMAL_TO_ERROR) {
background_color_animation_->Show();
} else if (animation == TranslateInfoBarDelegate::ERROR_TO_NORMAL) {
background_color_animation_->Reset(1.0);
background_color_animation_->Hide();
}
}
InfoBarView::ViewHierarchyChanged(details);
}
TranslateInfoBarDelegate* TranslateInfoBarBase::GetDelegate() {
return delegate()->AsTranslateInfoBarDelegate();
}
void TranslateInfoBarBase::OnPaintBackground(gfx::Canvas* canvas) {
const InfoBarContainer::Delegate* delegate = container_delegate();
if (delegate)
error_background_.set_separator_color(delegate->GetInfoBarSeparatorColor());
if (!background_color_animation_->is_animating()) {
GetBackground().Paint(canvas, this);
return;
}
FadeBackground(canvas, 1.0 - background_color_animation_->GetCurrentValue(),
*background());
FadeBackground(canvas, background_color_animation_->GetCurrentValue(),
error_background_);
}
void TranslateInfoBarBase::AnimationProgressed(
const gfx::Animation* animation) {
if (animation == background_color_animation_.get())
SchedulePaint();
else
InfoBarView::AnimationProgressed(animation);
}
const views::Background& TranslateInfoBarBase::GetBackground() {
return GetDelegate()->is_error() ? error_background_ : *background();
}
void TranslateInfoBarBase::FadeBackground(gfx::Canvas* canvas,
double animation_value,
const views::Background& background) {
canvas->SaveLayerAlpha(static_cast<int>(animation_value * 255));
background.Paint(canvas, this);
canvas->Restore();
}