Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Side by Side Diff: chrome/browser/ui/views/infobars/translate_infobar_base.cc

Issue 240193003: Move Infobars core files to the Infobars component (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix nib name on mac Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/translate/translate_tab_helper.h" 9 #include "chrome/browser/translate/translate_tab_helper.h"
11 #include "chrome/browser/ui/views/infobars/after_translate_infobar.h" 10 #include "chrome/browser/ui/views/infobars/after_translate_infobar.h"
12 #include "chrome/browser/ui/views/infobars/before_translate_infobar.h" 11 #include "chrome/browser/ui/views/infobars/before_translate_infobar.h"
13 #include "chrome/browser/ui/views/infobars/translate_message_infobar.h" 12 #include "chrome/browser/ui/views/infobars/translate_message_infobar.h"
13 #include "components/infobars/core/infobar.h"
14 #include "grit/theme_resources.h" 14 #include "grit/theme_resources.h"
15 #include "ui/base/resource/resource_bundle.h" 15 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/gfx/animation/slide_animation.h" 16 #include "ui/gfx/animation/slide_animation.h"
17 #include "ui/gfx/canvas.h" 17 #include "ui/gfx/canvas.h"
18 #include "ui/views/controls/button/menu_button.h" 18 #include "ui/views/controls/button/menu_button.h"
19 #include "ui/views/controls/label.h" 19 #include "ui/views/controls/label.h"
20 20
21 21
22 // TranslateInfoBarDelegate --------------------------------------------------- 22 // TranslateInfoBarDelegate ---------------------------------------------------
23 23
24 // static 24 // static
25 scoped_ptr<InfoBar> TranslateInfoBarDelegate::CreateInfoBar( 25 scoped_ptr<infobars::InfoBar> TranslateInfoBarDelegate::CreateInfoBar(
26 scoped_ptr<TranslateInfoBarDelegate> delegate) { 26 scoped_ptr<TranslateInfoBarDelegate> delegate) {
27 if (delegate->translate_step() == translate::TRANSLATE_STEP_BEFORE_TRANSLATE) 27 if (delegate->translate_step() ==
28 return scoped_ptr<InfoBar>(new BeforeTranslateInfoBar(delegate.Pass())); 28 translate::TRANSLATE_STEP_BEFORE_TRANSLATE) {
29 if (delegate->translate_step() == translate::TRANSLATE_STEP_AFTER_TRANSLATE) 29 return scoped_ptr<infobars::InfoBar>(
30 return scoped_ptr<InfoBar>(new AfterTranslateInfoBar(delegate.Pass())); 30 new BeforeTranslateInfoBar(delegate.Pass()));
31 return scoped_ptr<InfoBar>(new TranslateMessageInfoBar(delegate.Pass())); 31 }
32 if (delegate->translate_step() ==
33 translate::TRANSLATE_STEP_AFTER_TRANSLATE) {
34 return scoped_ptr<infobars::InfoBar>(
35 new AfterTranslateInfoBar(delegate.Pass()));
36 }
37 return scoped_ptr<infobars::InfoBar>(
38 new TranslateMessageInfoBar(delegate.Pass()));
32 } 39 }
33 40
34 41
35 // TranslateInfoBarBase ------------------------------------------------------- 42 // TranslateInfoBarBase -------------------------------------------------------
36 43
37 // static 44 // static
38 const int TranslateInfoBarBase::kButtonInLabelSpacing = 5; 45 const int TranslateInfoBarBase::kButtonInLabelSpacing = 5;
39 46
40 void TranslateInfoBarBase::UpdateLanguageButtonText( 47 void TranslateInfoBarBase::UpdateLanguageButtonText(
41 views::MenuButton* button, 48 views::MenuButton* button,
42 const base::string16& text) { 49 const base::string16& text) {
43 DCHECK(button); 50 DCHECK(button);
44 button->SetText(text); 51 button->SetText(text);
45 button->ClearMaxTextSize(); 52 button->ClearMaxTextSize();
46 button->SizeToPreferredSize(); 53 button->SizeToPreferredSize();
47 Layout(); 54 Layout();
48 SchedulePaint(); 55 SchedulePaint();
49 } 56 }
50 57
51 TranslateInfoBarBase::TranslateInfoBarBase( 58 TranslateInfoBarBase::TranslateInfoBarBase(
52 scoped_ptr<TranslateInfoBarDelegate> delegate) 59 scoped_ptr<TranslateInfoBarDelegate> delegate)
53 : InfoBarView(delegate.PassAs<InfoBarDelegate>()), 60 : InfoBarView(delegate.PassAs<infobars::InfoBarDelegate>()),
54 error_background_(InfoBarDelegate::WARNING_TYPE) { 61 error_background_(infobars::InfoBarDelegate::WARNING_TYPE) {
55 } 62 }
56 63
57 TranslateInfoBarBase::~TranslateInfoBarBase() { 64 TranslateInfoBarBase::~TranslateInfoBarBase() {
58 } 65 }
59 66
60 void TranslateInfoBarBase::ViewHierarchyChanged( 67 void TranslateInfoBarBase::ViewHierarchyChanged(
61 const ViewHierarchyChangedDetails& details) { 68 const ViewHierarchyChangedDetails& details) {
62 if (details.is_add && (details.child == this) && 69 if (details.is_add && (details.child == this) &&
63 (background_color_animation_ == NULL)) { 70 (background_color_animation_ == NULL)) {
64 background_color_animation_.reset(new gfx::SlideAnimation(this)); 71 background_color_animation_.reset(new gfx::SlideAnimation(this));
(...skipping 15 matching lines...) Expand all
80 InfoBarView::ViewHierarchyChanged(details); 87 InfoBarView::ViewHierarchyChanged(details);
81 } 88 }
82 89
83 TranslateInfoBarDelegate* TranslateInfoBarBase::GetDelegate() { 90 TranslateInfoBarDelegate* TranslateInfoBarBase::GetDelegate() {
84 return delegate()->AsTranslateInfoBarDelegate(); 91 return delegate()->AsTranslateInfoBarDelegate();
85 } 92 }
86 93
87 void TranslateInfoBarBase::OnPaintBackground(gfx::Canvas* canvas) { 94 void TranslateInfoBarBase::OnPaintBackground(gfx::Canvas* canvas) {
88 // We need to set the separator color for |error_background_| like 95 // We need to set the separator color for |error_background_| like
89 // InfoBarView::Layout() does for the normal background. 96 // InfoBarView::Layout() does for the normal background.
90 const InfoBarContainer::Delegate* delegate = container_delegate(); 97 const infobars::InfoBarContainer::Delegate* delegate = container_delegate();
91 if (delegate) 98 if (delegate)
92 error_background_.set_separator_color(delegate->GetInfoBarSeparatorColor()); 99 error_background_.set_separator_color(delegate->GetInfoBarSeparatorColor());
93 100
94 // If we're not animating, simply paint the background for the current state. 101 // If we're not animating, simply paint the background for the current state.
95 if (!background_color_animation_->is_animating()) { 102 if (!background_color_animation_->is_animating()) {
96 GetBackground().Paint(canvas, this); 103 GetBackground().Paint(canvas, this);
97 return; 104 return;
98 } 105 }
99 106
100 FadeBackground(canvas, 1.0 - background_color_animation_->GetCurrentValue(), 107 FadeBackground(canvas, 1.0 - background_color_animation_->GetCurrentValue(),
(...skipping 16 matching lines...) Expand all
117 124
118 void TranslateInfoBarBase::FadeBackground(gfx::Canvas* canvas, 125 void TranslateInfoBarBase::FadeBackground(gfx::Canvas* canvas,
119 double animation_value, 126 double animation_value,
120 const views::Background& background) { 127 const views::Background& background) {
121 // Draw the background into an offscreen buffer with alpha value per animation 128 // Draw the background into an offscreen buffer with alpha value per animation
122 // value, then blend it back into the current canvas. 129 // value, then blend it back into the current canvas.
123 canvas->SaveLayerAlpha(static_cast<int>(animation_value * 255)); 130 canvas->SaveLayerAlpha(static_cast<int>(animation_value * 255));
124 background.Paint(canvas, this); 131 background.Paint(canvas, this);
125 canvas->Restore(); 132 canvas->Restore();
126 } 133 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698