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_delegate.h" | 10 #include "chrome/browser/translate/translate_infobar_delegate.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 View::ConvertPointToScreen(menu_button, &menu_position); | 129 View::ConvertPointToScreen(menu_button, &menu_position); |
130 #if defined(OS_WIN) | 130 #if defined(OS_WIN) |
131 int left_bound = GetSystemMetrics(SM_XVIRTUALSCREEN); | 131 int left_bound = GetSystemMetrics(SM_XVIRTUALSCREEN); |
132 if (menu_position.x() < left_bound) | 132 if (menu_position.x() < left_bound) |
133 menu_position.set_x(left_bound); | 133 menu_position.set_x(left_bound); |
134 #endif | 134 #endif |
135 return menu_position; | 135 return menu_position; |
136 } | 136 } |
137 | 137 |
138 TranslateInfoBarDelegate* TranslateInfoBarBase::GetDelegate() const { | 138 TranslateInfoBarDelegate* TranslateInfoBarBase::GetDelegate() const { |
139 return static_cast<TranslateInfoBarDelegate*>(delegate()); | 139 return delegate()->AsTranslateInfoBarDelegate(); |
140 } | 140 } |
141 | 141 |
142 const InfoBarBackground& TranslateInfoBarBase::GetBackground() const { | 142 const InfoBarBackground& TranslateInfoBarBase::GetBackground() const { |
143 return GetDelegate()->IsError() ? error_background_ : normal_background_; | 143 return (delegate() && GetDelegate()->IsError()) ? |
| 144 error_background_ : normal_background_; |
144 } | 145 } |
145 | 146 |
146 void TranslateInfoBarBase::FadeBackground(gfx::Canvas* canvas, | 147 void TranslateInfoBarBase::FadeBackground(gfx::Canvas* canvas, |
147 double animation_value, | 148 double animation_value, |
148 const InfoBarBackground& background) { | 149 const InfoBarBackground& background) { |
149 // Draw the background into an offscreen buffer with alpha value per animation | 150 // Draw the background into an offscreen buffer with alpha value per animation |
150 // value, then blend it back into the current canvas. | 151 // value, then blend it back into the current canvas. |
151 canvas->SaveLayerAlpha(static_cast<int>(animation_value * 255)); | 152 canvas->SaveLayerAlpha(static_cast<int>(animation_value * 255)); |
152 canvas->AsCanvasSkia()->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); | 153 canvas->AsCanvasSkia()->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); |
153 background.Paint(canvas, this); | 154 background.Paint(canvas, this); |
(...skipping 15 matching lines...) Expand all Loading... |
169 infobar = new TranslateMessageInfoBar(this); | 170 infobar = new TranslateMessageInfoBar(this); |
170 break; | 171 break; |
171 default: | 172 default: |
172 NOTREACHED(); | 173 NOTREACHED(); |
173 } | 174 } |
174 // 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 |
175 // changes. | 176 // changes. |
176 infobar_view_ = infobar; | 177 infobar_view_ = infobar; |
177 return infobar; | 178 return infobar; |
178 } | 179 } |
OLD | NEW |