| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/infobars/translate_infobar_base.h" | 5 #include "chrome/browser/views/infobars/translate_infobar_base.h" |
| 6 | 6 |
| 7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
| 8 #include "app/slide_animation.h" | 8 #include "app/slide_animation.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/translate/translate_infobar_delegate2.h" | 10 #include "chrome/browser/translate/translate_infobar_delegate2.h" |
| 11 #include "chrome/browser/views/infobars/after_translate_infobar.h" | 11 #include "chrome/browser/views/infobars/after_translate_infobar.h" |
| 12 #include "chrome/browser/views/infobars/before_translate_infobar.h" | 12 #include "chrome/browser/views/infobars/before_translate_infobar.h" |
| 13 #include "chrome/browser/views/infobars/translate_message_infobar.h" | 13 #include "chrome/browser/views/infobars/translate_message_infobar.h" |
| 14 #include "chrome/browser/views/infobars/infobar_button_border.h" | 14 #include "chrome/browser/views/infobars/infobar_button_border.h" |
| 15 #include "gfx/canvas_skia.h" | 15 #include "gfx/canvas.h" |
| 16 #include "grit/app_resources.h" | 16 #include "grit/app_resources.h" |
| 17 #include "views/controls/button/menu_button.h" | 17 #include "views/controls/button/menu_button.h" |
| 18 #include "views/controls/image_view.h" | 18 #include "views/controls/image_view.h" |
| 19 | 19 |
| 20 TranslateInfoBarBase::TranslateInfoBarBase( | 20 TranslateInfoBarBase::TranslateInfoBarBase( |
| 21 TranslateInfoBarDelegate2* delegate) | 21 TranslateInfoBarDelegate2* delegate) |
| 22 : InfoBar(delegate), | 22 : InfoBar(delegate), |
| 23 normal_background_(InfoBarDelegate::PAGE_ACTION_TYPE), | 23 normal_background_(InfoBarDelegate::PAGE_ACTION_TYPE), |
| 24 error_background_(InfoBarDelegate::ERROR_TYPE) { | 24 error_background_(InfoBarDelegate::ERROR_TYPE) { |
| 25 icon_ = new views::ImageView; | 25 icon_ = new views::ImageView; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 | 141 |
| 142 const InfoBarBackground& TranslateInfoBarBase::GetBackground() const { | 142 const InfoBarBackground& TranslateInfoBarBase::GetBackground() const { |
| 143 return GetDelegate()->IsError() ? error_background_ : normal_background_; | 143 return GetDelegate()->IsError() ? error_background_ : normal_background_; |
| 144 } | 144 } |
| 145 | 145 |
| 146 void TranslateInfoBarBase::FadeBackground(gfx::Canvas* canvas, | 146 void TranslateInfoBarBase::FadeBackground(gfx::Canvas* canvas, |
| 147 double animation_value, | 147 double animation_value, |
| 148 const InfoBarBackground& background) { | 148 const InfoBarBackground& background) { |
| 149 // Draw the background into an offscreen buffer with alpha value per animation | 149 // Draw the background into an offscreen buffer with alpha value per animation |
| 150 // value, then blend it back into the current canvas. | 150 // value, then blend it back into the current canvas. |
| 151 canvas->AsCanvasSkia()->saveLayerAlpha( | 151 canvas->saveLayerAlpha(NULL, static_cast<int>(animation_value * 255), |
| 152 NULL, static_cast<int>(animation_value * 255), | 152 SkCanvas::kARGB_NoClipLayer_SaveFlag); |
| 153 SkCanvas::kARGB_NoClipLayer_SaveFlag); | 153 canvas->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); |
| 154 canvas->AsCanvasSkia()->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); | |
| 155 background.Paint(canvas, this); | 154 background.Paint(canvas, this); |
| 156 canvas->AsCanvasSkia()->restore(); | 155 canvas->restore(); |
| 157 } | 156 } |
| 158 | 157 |
| 159 // TranslateInfoBarDelegate views specific method: | 158 // TranslateInfoBarDelegate views specific method: |
| 160 InfoBar* TranslateInfoBarDelegate2::CreateInfoBar() { | 159 InfoBar* TranslateInfoBarDelegate2::CreateInfoBar() { |
| 161 TranslateInfoBarBase* infobar = NULL; | 160 TranslateInfoBarBase* infobar = NULL; |
| 162 switch (type_) { | 161 switch (type_) { |
| 163 case BEFORE_TRANSLATE: | 162 case BEFORE_TRANSLATE: |
| 164 infobar = new BeforeTranslateInfoBar(this); | 163 infobar = new BeforeTranslateInfoBar(this); |
| 165 break; | 164 break; |
| 166 case AFTER_TRANSLATE: | 165 case AFTER_TRANSLATE: |
| 167 infobar = new AfterTranslateInfoBar(this); | 166 infobar = new AfterTranslateInfoBar(this); |
| 168 break; | 167 break; |
| 169 case TRANSLATING: | 168 case TRANSLATING: |
| 170 case TRANSLATION_ERROR: | 169 case TRANSLATION_ERROR: |
| 171 infobar = new TranslateMessageInfoBar(this); | 170 infobar = new TranslateMessageInfoBar(this); |
| 172 break; | 171 break; |
| 173 default: | 172 default: |
| 174 NOTREACHED(); | 173 NOTREACHED(); |
| 175 } | 174 } |
| 176 // Set |infobar_view_| so that the model can notify the infobar when it | 175 // Set |infobar_view_| so that the model can notify the infobar when it |
| 177 // changes. | 176 // changes. |
| 178 infobar_view_ = infobar; | 177 infobar_view_ = infobar; |
| 179 return infobar; | 178 return infobar; |
| 180 } | 179 } |
| OLD | NEW |