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/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" |
11 #include "chrome/browser/ui/views/infobars/translate_message_infobar.h" | 11 #include "chrome/browser/ui/views/infobars/translate_message_infobar.h" |
12 #include "grit/theme_resources.h" | 12 #include "grit/theme_resources.h" |
13 #include "ui/base/animation/slide_animation.h" | |
14 #include "ui/base/resource/resource_bundle.h" | 13 #include "ui/base/resource/resource_bundle.h" |
| 14 #include "ui/gfx/animation/slide_animation.h" |
15 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
16 #include "ui/views/controls/button/menu_button.h" | 16 #include "ui/views/controls/button/menu_button.h" |
17 #include "ui/views/controls/label.h" | 17 #include "ui/views/controls/label.h" |
18 | 18 |
19 | 19 |
20 // TranslateInfoBarDelegate --------------------------------------------------- | 20 // TranslateInfoBarDelegate --------------------------------------------------- |
21 | 21 |
22 InfoBar* TranslateInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { | 22 InfoBar* TranslateInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { |
23 if (infobar_type_ == BEFORE_TRANSLATE) | 23 if (infobar_type_ == BEFORE_TRANSLATE) |
24 return new BeforeTranslateInfoBar(owner, this); | 24 return new BeforeTranslateInfoBar(owner, this); |
(...skipping 23 matching lines...) Expand all Loading... |
48 error_background_(InfoBarDelegate::WARNING_TYPE) { | 48 error_background_(InfoBarDelegate::WARNING_TYPE) { |
49 } | 49 } |
50 | 50 |
51 TranslateInfoBarBase::~TranslateInfoBarBase() { | 51 TranslateInfoBarBase::~TranslateInfoBarBase() { |
52 } | 52 } |
53 | 53 |
54 void TranslateInfoBarBase::ViewHierarchyChanged( | 54 void TranslateInfoBarBase::ViewHierarchyChanged( |
55 const ViewHierarchyChangedDetails& details) { | 55 const ViewHierarchyChangedDetails& details) { |
56 if (details.is_add && (details.child == this) && | 56 if (details.is_add && (details.child == this) && |
57 (background_color_animation_ == NULL)) { | 57 (background_color_animation_ == NULL)) { |
58 background_color_animation_.reset(new ui::SlideAnimation(this)); | 58 background_color_animation_.reset(new gfx::SlideAnimation(this)); |
59 background_color_animation_->SetTweenType(ui::Tween::LINEAR); | 59 background_color_animation_->SetTweenType(gfx::Tween::LINEAR); |
60 background_color_animation_->SetSlideDuration(500); | 60 background_color_animation_->SetSlideDuration(500); |
61 TranslateInfoBarDelegate::BackgroundAnimationType animation = | 61 TranslateInfoBarDelegate::BackgroundAnimationType animation = |
62 GetDelegate()->background_animation_type(); | 62 GetDelegate()->background_animation_type(); |
63 if (animation == TranslateInfoBarDelegate::NORMAL_TO_ERROR) { | 63 if (animation == TranslateInfoBarDelegate::NORMAL_TO_ERROR) { |
64 background_color_animation_->Show(); | 64 background_color_animation_->Show(); |
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 } |
(...skipping 20 matching lines...) Expand all Loading... |
90 GetBackground().Paint(canvas, this); | 90 GetBackground().Paint(canvas, this); |
91 return; | 91 return; |
92 } | 92 } |
93 | 93 |
94 FadeBackground(canvas, 1.0 - background_color_animation_->GetCurrentValue(), | 94 FadeBackground(canvas, 1.0 - background_color_animation_->GetCurrentValue(), |
95 *background()); | 95 *background()); |
96 FadeBackground(canvas, background_color_animation_->GetCurrentValue(), | 96 FadeBackground(canvas, background_color_animation_->GetCurrentValue(), |
97 error_background_); | 97 error_background_); |
98 } | 98 } |
99 | 99 |
100 void TranslateInfoBarBase::AnimationProgressed(const ui::Animation* animation) { | 100 void TranslateInfoBarBase::AnimationProgressed( |
| 101 const gfx::Animation* animation) { |
101 if (animation == background_color_animation_.get()) | 102 if (animation == background_color_animation_.get()) |
102 SchedulePaint(); // That'll trigger a PaintBackgroud. | 103 SchedulePaint(); // That'll trigger a PaintBackgroud. |
103 else | 104 else |
104 InfoBarView::AnimationProgressed(animation); | 105 InfoBarView::AnimationProgressed(animation); |
105 } | 106 } |
106 | 107 |
107 const views::Background& TranslateInfoBarBase::GetBackground() { | 108 const views::Background& TranslateInfoBarBase::GetBackground() { |
108 return GetDelegate()->is_error() ? error_background_ : *background(); | 109 return GetDelegate()->is_error() ? error_background_ : *background(); |
109 } | 110 } |
110 | 111 |
111 void TranslateInfoBarBase::FadeBackground(gfx::Canvas* canvas, | 112 void TranslateInfoBarBase::FadeBackground(gfx::Canvas* canvas, |
112 double animation_value, | 113 double animation_value, |
113 const views::Background& background) { | 114 const views::Background& background) { |
114 // 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 |
115 // value, then blend it back into the current canvas. | 116 // value, then blend it back into the current canvas. |
116 canvas->SaveLayerAlpha(static_cast<int>(animation_value * 255)); | 117 canvas->SaveLayerAlpha(static_cast<int>(animation_value * 255)); |
117 background.Paint(canvas, this); | 118 background.Paint(canvas, this); |
118 canvas->Restore(); | 119 canvas->Restore(); |
119 } | 120 } |
OLD | NEW |