OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/location_bar/origin_chip_view.h" | 5 #include "chrome/browser/ui/views/location_bar/origin_chip_view.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 18 matching lines...) Expand all Loading... | |
29 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
30 #include "content/public/common/url_constants.h" | 30 #include "content/public/common/url_constants.h" |
31 #include "extensions/browser/extension_system.h" | 31 #include "extensions/browser/extension_system.h" |
32 #include "extensions/common/constants.h" | 32 #include "extensions/common/constants.h" |
33 #include "extensions/common/manifest_handlers/icons_handler.h" | 33 #include "extensions/common/manifest_handlers/icons_handler.h" |
34 #include "grit/generated_resources.h" | 34 #include "grit/generated_resources.h" |
35 #include "grit/theme_resources.h" | 35 #include "grit/theme_resources.h" |
36 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
37 #include "ui/base/resource/resource_bundle.h" | 37 #include "ui/base/resource/resource_bundle.h" |
38 #include "ui/base/theme_provider.h" | 38 #include "ui/base/theme_provider.h" |
39 #include "ui/gfx/animation/slide_animation.h" | |
40 #include "ui/gfx/canvas.h" | 39 #include "ui/gfx/canvas.h" |
41 #include "ui/gfx/font_list.h" | 40 #include "ui/gfx/font_list.h" |
41 #include "ui/gfx/text_utils.h" | |
42 #include "ui/views/background.h" | 42 #include "ui/views/background.h" |
43 #include "ui/views/controls/button/label_button.h" | 43 #include "ui/views/controls/button/label_button.h" |
44 #include "ui/views/controls/button/label_button_border.h" | 44 #include "ui/views/controls/button/label_button_border.h" |
45 #include "ui/views/painter.h" | 45 #include "ui/views/painter.h" |
46 | 46 |
47 | 47 |
48 // OriginChipExtensionIcon ---------------------------------------------------- | 48 // OriginChipExtensionIcon ---------------------------------------------------- |
49 | 49 |
50 class OriginChipExtensionIcon : public extensions::IconImage::Observer { | 50 class OriginChipExtensionIcon : public extensions::IconImage::Observer { |
51 public: | 51 public: |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 | 95 |
96 | 96 |
97 // OriginChipView ------------------------------------------------------------- | 97 // OriginChipView ------------------------------------------------------------- |
98 | 98 |
99 namespace { | 99 namespace { |
100 | 100 |
101 const int kEdgeThickness = 5; | 101 const int kEdgeThickness = 5; |
102 const int k16x16IconLeadingSpacing = 1; | 102 const int k16x16IconLeadingSpacing = 1; |
103 const int k16x16IconTrailingSpacing = 2; | 103 const int k16x16IconTrailingSpacing = 2; |
104 const int kIconTextSpacing = 3; | 104 const int kIconTextSpacing = 3; |
105 const int kTrailingLabelMargin = 0; | |
106 | 105 |
107 const int kNormalImages[3][9] = { | 106 const int kNormalImages[3][9] = { |
108 IMAGE_GRID(IDR_ORIGIN_CHIP_NORMAL), | 107 IMAGE_GRID(IDR_ORIGIN_CHIP_NORMAL), |
109 IMAGE_GRID(IDR_ORIGIN_CHIP_HOVER), | 108 IMAGE_GRID(IDR_ORIGIN_CHIP_HOVER), |
110 IMAGE_GRID(IDR_ORIGIN_CHIP_PRESSED) | 109 IMAGE_GRID(IDR_ORIGIN_CHIP_PRESSED) |
111 }; | 110 }; |
112 | 111 |
113 const int kMalwareImages[3][9] = { | 112 const int kMalwareImages[3][9] = { |
114 IMAGE_GRID(IDR_ORIGIN_CHIP_MALWARE_NORMAL), | 113 IMAGE_GRID(IDR_ORIGIN_CHIP_MALWARE_NORMAL), |
115 IMAGE_GRID(IDR_ORIGIN_CHIP_MALWARE_HOVER), | 114 IMAGE_GRID(IDR_ORIGIN_CHIP_MALWARE_HOVER), |
(...skipping 13 matching lines...) Expand all Loading... | |
129 }; | 128 }; |
130 | 129 |
131 } // namespace | 130 } // namespace |
132 | 131 |
133 OriginChipView::OriginChipView(LocationBarView* location_bar_view, | 132 OriginChipView::OriginChipView(LocationBarView* location_bar_view, |
134 Profile* profile, | 133 Profile* profile, |
135 const gfx::FontList& font_list) | 134 const gfx::FontList& font_list) |
136 : LabelButton(this, base::string16()), | 135 : LabelButton(this, base::string16()), |
137 location_bar_view_(location_bar_view), | 136 location_bar_view_(location_bar_view), |
138 profile_(profile), | 137 profile_(profile), |
139 showing_16x16_icon_(false) { | 138 showing_16x16_icon_(false), |
139 fade_in_animation_(this) { | |
140 scoped_refptr<SafeBrowsingService> sb_service = | 140 scoped_refptr<SafeBrowsingService> sb_service = |
141 g_browser_process->safe_browsing_service(); | 141 g_browser_process->safe_browsing_service(); |
142 // May not be set for unit tests. | 142 // May not be set for unit tests. |
143 if (sb_service && sb_service->ui_manager()) | 143 if (sb_service && sb_service->ui_manager()) |
144 sb_service->ui_manager()->AddObserver(this); | 144 sb_service->ui_manager()->AddObserver(this); |
145 | 145 |
146 SetFontList(font_list); | 146 SetFontList(font_list); |
147 | 147 |
148 image()->EnableCanvasFlippingForRTLUI(false); | 148 image()->EnableCanvasFlippingForRTLUI(false); |
149 | 149 |
150 // TODO(gbillock): Would be nice to just use stock LabelButton stuff here. | 150 // TODO(gbillock): Would be nice to just use stock LabelButton stuff here. |
151 location_icon_view_ = new LocationIconView(location_bar_view_); | 151 location_icon_view_ = new LocationIconView(location_bar_view_); |
152 // Make location icon hover events count as hovering the origin chip. | 152 // Make location icon hover events count as hovering the origin chip. |
153 location_icon_view_->set_interactive(false); | 153 location_icon_view_->set_interactive(false); |
154 location_icon_view_->ShowTooltip(true); | 154 location_icon_view_->ShowTooltip(true); |
155 AddChildView(location_icon_view_); | 155 AddChildView(location_icon_view_); |
156 | 156 |
157 ev_label_ = new views::Label(base::string16(), GetFontList()); | |
158 ev_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
159 ev_label_->SetElideBehavior(views::Label::NO_ELIDE); | |
160 AddChildView(ev_label_); | |
161 | |
157 host_label_ = new views::Label(base::string16(), GetFontList()); | 162 host_label_ = new views::Label(base::string16(), GetFontList()); |
163 host_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
164 host_label_->SetElideBehavior(views::Label::NO_ELIDE); | |
158 AddChildView(host_label_); | 165 AddChildView(host_label_); |
159 | 166 |
160 fade_in_animation_.reset(new gfx::SlideAnimation(this)); | 167 fade_in_animation_.SetTweenType(gfx::Tween::LINEAR_OUT_SLOW_IN); |
161 fade_in_animation_->SetTweenType(gfx::Tween::LINEAR); | 168 fade_in_animation_.SetSlideDuration(175); |
162 fade_in_animation_->SetSlideDuration(300); | |
163 } | 169 } |
164 | 170 |
165 OriginChipView::~OriginChipView() { | 171 OriginChipView::~OriginChipView() { |
166 scoped_refptr<SafeBrowsingService> sb_service = | 172 scoped_refptr<SafeBrowsingService> sb_service = |
167 g_browser_process->safe_browsing_service(); | 173 g_browser_process->safe_browsing_service(); |
168 if (sb_service.get() && sb_service->ui_manager()) | 174 if (sb_service.get() && sb_service->ui_manager()) |
169 sb_service->ui_manager()->RemoveObserver(this); | 175 sb_service->ui_manager()->RemoveObserver(this); |
170 } | 176 } |
171 | 177 |
172 void OriginChipView::Update(content::WebContents* web_contents) { | 178 void OriginChipView::OnChanged() { |
179 content::WebContents* web_contents = location_bar_view_->GetWebContents(); | |
173 if (!web_contents) | 180 if (!web_contents) |
174 return; | 181 return; |
175 | 182 |
176 // Note: security level can change async as the connection is made. | 183 // Note: security level can change async as the connection is made. |
177 GURL url = location_bar_view_->GetToolbarModel()->GetURL(); | 184 GURL url = location_bar_view_->GetToolbarModel()->GetURL(); |
178 const ToolbarModel::SecurityLevel security_level = | 185 const ToolbarModel::SecurityLevel security_level = |
179 location_bar_view_->GetToolbarModel()->GetSecurityLevel(true); | 186 location_bar_view_->GetToolbarModel()->GetSecurityLevel(true); |
180 | 187 |
181 bool url_malware = OriginChip::IsMalware(url, web_contents); | 188 bool url_malware = OriginChip::IsMalware(url, web_contents); |
182 | 189 |
(...skipping 13 matching lines...) Expand all Loading... | |
196 if (url_malware_) { | 203 if (url_malware_) { |
197 SetBorderImages(kMalwareImages); | 204 SetBorderImages(kMalwareImages); |
198 } else if (security_level_ == ToolbarModel::SECURITY_ERROR) { | 205 } else if (security_level_ == ToolbarModel::SECURITY_ERROR) { |
199 SetBorderImages(kBrokenSSLImages); | 206 SetBorderImages(kBrokenSSLImages); |
200 } else if (security_level_ == ToolbarModel::EV_SECURE) { | 207 } else if (security_level_ == ToolbarModel::EV_SECURE) { |
201 SetBorderImages(kEVImages); | 208 SetBorderImages(kEVImages); |
202 } else { | 209 } else { |
203 SetBorderImages(kNormalImages); | 210 SetBorderImages(kNormalImages); |
204 } | 211 } |
205 | 212 |
213 ev_label_->SetText(location_bar_view_->GetToolbarModel()->GetEVCertName()); | |
214 ev_label_->SetVisible(security_level_ == ToolbarModel::EV_SECURE); | |
215 | |
216 // TODO(pkasting): Allow the origin chip to shrink, and use ElideHost(). | |
206 base::string16 host = | 217 base::string16 host = |
207 OriginChip::LabelFromURLForProfile(url_displayed_, profile_); | 218 OriginChip::LabelFromURLForProfile(url_displayed_, profile_); |
208 if (security_level_ == ToolbarModel::EV_SECURE) { | |
209 host = l10n_util::GetStringFUTF16(IDS_SITE_CHIP_EV_SSL_LABEL, | |
210 location_bar_view_->GetToolbarModel()->GetEVCertName(), | |
211 host); | |
212 } | |
213 host_label_->SetText(host); | 219 host_label_->SetText(host); |
214 host_label_->SetTooltipText(base::UTF8ToUTF16(url.spec())); | 220 host_label_->SetTooltipText(base::UTF8ToUTF16(url.spec())); |
215 host_label_->SetElideBehavior(views::Label::NO_ELIDE); | |
216 | 221 |
217 int icon = location_bar_view_->GetToolbarModel()->GetIconForSecurityLevel( | 222 int icon = location_bar_view_->GetToolbarModel()->GetIconForSecurityLevel( |
218 security_level_); | 223 security_level_); |
219 showing_16x16_icon_ = false; | 224 showing_16x16_icon_ = false; |
220 | 225 |
221 if (url_displayed_.is_empty() || | 226 if (url_displayed_.is_empty() || |
222 url_displayed_.SchemeIs(content::kChromeUIScheme)) { | 227 url_displayed_.SchemeIs(content::kChromeUIScheme)) { |
223 icon = IDR_PRODUCT_LOGO_16; | 228 icon = IDR_PRODUCT_LOGO_16; |
224 showing_16x16_icon_ = true; | 229 showing_16x16_icon_ = true; |
225 } | 230 } |
226 | 231 |
227 location_icon_view_->SetImage(GetThemeProvider()->GetImageSkiaNamed(icon)); | 232 location_icon_view_->SetImage(GetThemeProvider()->GetImageSkiaNamed(icon)); |
228 | 233 |
229 if (url_displayed_.SchemeIs(extensions::kExtensionScheme)) { | 234 if (url_displayed_.SchemeIs(extensions::kExtensionScheme)) { |
230 icon = IDR_EXTENSIONS_FAVICON; | 235 icon = IDR_EXTENSIONS_FAVICON; |
231 showing_16x16_icon_ = true; | 236 showing_16x16_icon_ = true; |
232 location_icon_view_->SetImage(GetThemeProvider()->GetImageSkiaNamed(icon)); | 237 location_icon_view_->SetImage(GetThemeProvider()->GetImageSkiaNamed(icon)); |
233 | 238 |
234 ExtensionService* service = | 239 ExtensionService* service = |
235 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 240 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
236 const extensions::Extension* extension = | 241 const extensions::Extension* extension = |
237 service->extensions()->GetExtensionOrAppByURL(url_displayed_); | 242 service->extensions()->GetExtensionOrAppByURL(url_displayed_); |
238 extension_icon_.reset( | 243 extension_icon_.reset( |
239 new OriginChipExtensionIcon(location_icon_view_, profile_, extension)); | 244 new OriginChipExtensionIcon(location_icon_view_, profile_, extension)); |
240 } else { | 245 } else { |
241 extension_icon_.reset(); | 246 extension_icon_.reset(); |
242 } | 247 } |
243 | 248 |
244 Layout(); | 249 if (visible()) { |
245 SchedulePaint(); | 250 CancelFade(); |
Justin Donnelly
2014/05/29 21:37:29
Is this intended to cover navigation while the chi
Peter Kasting
2014/05/29 23:32:16
Yes, basically. Anything that changes the visible
| |
246 } | 251 Layout(); |
247 | 252 SchedulePaint(); |
248 void OriginChipView::OnChanged() { | 253 } |
249 Update(location_bar_view_->GetWebContents()); | |
250 // TODO(gbillock): Also need to potentially repaint infobars to make sure the | |
251 // arrows are pointing to the right spot. Only needed for some edge cases. | |
252 } | |
253 | |
254 int OriginChipView::ElideDomainTarget(int target_max_width) { | |
255 base::string16 host = | |
256 OriginChip::LabelFromURLForProfile(url_displayed_, profile_); | |
257 host_label_->SetText(host); | |
258 int width = GetPreferredSize().width(); | |
259 if (width <= target_max_width) | |
260 return width; | |
261 | |
262 gfx::Size label_size = host_label_->GetPreferredSize(); | |
263 int padding_width = width - label_size.width(); | |
264 | |
265 host_label_->SetText(ElideHost( | |
266 location_bar_view_->GetToolbarModel()->GetURL(), | |
267 host_label_->font_list(), target_max_width - padding_width)); | |
268 return GetPreferredSize().width(); | |
269 } | 254 } |
270 | 255 |
271 void OriginChipView::FadeIn() { | 256 void OriginChipView::FadeIn() { |
272 fade_in_animation_->Show(); | 257 fade_in_animation_.Show(); |
258 } | |
259 | |
260 void OriginChipView::CancelFade() { | |
261 fade_in_animation_.Stop(); | |
262 } | |
263 | |
264 int OriginChipView::HostLabelOffset() const { | |
265 return host_label_->x() - GetLabelX(); | |
273 } | 266 } |
274 | 267 |
275 gfx::Size OriginChipView::GetPreferredSize() const { | 268 gfx::Size OriginChipView::GetPreferredSize() const { |
276 gfx::Size label_size = host_label_->GetPreferredSize(); | 269 // TODO(pkasting): Use of " " here is a horrible hack, to be replaced by |
277 gfx::Size icon_size = location_icon_view_->GetPreferredSize(); | 270 // splitting the chip into separate pieces for EV/host. |
278 int icon_spacing = showing_16x16_icon_ ? | 271 int label_size = host_label_->GetPreferredSize().width(); |
279 (k16x16IconLeadingSpacing + k16x16IconTrailingSpacing) : 0; | 272 if (ev_label_->visible()) { |
280 return gfx::Size(kEdgeThickness + icon_size.width() + icon_spacing + | 273 label_size += ev_label_->GetPreferredSize().width() + |
281 kIconTextSpacing + label_size.width() + | 274 gfx::GetStringWidth(base::ASCIIToUTF16(" "), GetFontList()); |
282 kTrailingLabelMargin + kEdgeThickness, | 275 } |
283 icon_size.height()); | 276 return gfx::Size(GetLabelX() + label_size + kEdgeThickness, |
284 } | 277 location_icon_view_->GetPreferredSize().height()); |
285 | |
286 void OriginChipView::SetBorderImages(const int images[3][9]) { | |
287 scoped_ptr<views::LabelButtonBorder> border( | |
288 new views::LabelButtonBorder(views::Button::STYLE_BUTTON)); | |
289 | |
290 views::Painter* painter = views::Painter::CreateImageGridPainter(images[0]); | |
291 border->SetPainter(false, Button::STATE_NORMAL, painter); | |
292 painter = views::Painter::CreateImageGridPainter(images[1]); | |
293 border->SetPainter(false, Button::STATE_HOVERED, painter); | |
294 painter = views::Painter::CreateImageGridPainter(images[2]); | |
295 border->SetPainter(false, Button::STATE_PRESSED, painter); | |
296 | |
297 SetBorder(border.PassAs<views::Border>()); | |
298 | |
299 // Calculate a representative background color of the provided image grid and | |
300 // set it as the background color of the host label in order to color the text | |
301 // appropriately. We grab the color of the middle pixel of the middle image | |
302 // of the background, which we treat as the representative color of the entire | |
303 // background (reasonable, given the current appearance of these images). | |
304 const SkBitmap& bitmap( | |
305 GetThemeProvider()->GetImageSkiaNamed( | |
306 images[0][4])->GetRepresentation(1.0f).sk_bitmap()); | |
307 SkAutoLockPixels pixel_lock(bitmap); | |
308 host_label_->SetBackgroundColor( | |
309 bitmap.getColor(bitmap.width() / 2, bitmap.height() / 2)); | |
310 } | |
311 | |
312 void OriginChipView::AnimationProgressed(const gfx::Animation* animation) { | |
313 if (animation == fade_in_animation_.get()) | |
314 SchedulePaint(); | |
315 else | |
316 views::LabelButton::AnimationProgressed(animation); | |
317 } | |
318 | |
319 void OriginChipView::AnimationEnded(const gfx::Animation* animation) { | |
320 if (animation == fade_in_animation_.get()) | |
321 fade_in_animation_->Reset(); | |
322 else | |
323 views::LabelButton::AnimationEnded(animation); | |
324 } | 278 } |
325 | 279 |
326 void OriginChipView::Layout() { | 280 void OriginChipView::Layout() { |
327 // TODO(gbillock): Eventually we almost certainly want to use | 281 // TODO(gbillock): Eventually we almost certainly want to use |
328 // LocationBarLayout for leading and trailing decorations. | 282 // LocationBarLayout for leading and trailing decorations. |
329 | 283 |
330 location_icon_view_->SetBounds( | 284 location_icon_view_->SetBounds( |
331 kEdgeThickness + (showing_16x16_icon_ ? k16x16IconLeadingSpacing : 0), | 285 kEdgeThickness + (showing_16x16_icon_ ? k16x16IconLeadingSpacing : 0), |
332 LocationBarView::kNormalEdgeThickness, | 286 LocationBarView::kNormalEdgeThickness, |
333 location_icon_view_->GetPreferredSize().width(), | 287 location_icon_view_->GetPreferredSize().width(), |
334 height() - 2 * LocationBarView::kNormalEdgeThickness); | 288 height() - 2 * LocationBarView::kNormalEdgeThickness); |
335 | 289 |
336 int host_label_x = location_icon_view_->x() + location_icon_view_->width() + | 290 int label_x = GetLabelX(); |
337 kIconTextSpacing; | 291 int label_width = std::max(0, width() - label_x - kEdgeThickness); |
338 host_label_x += showing_16x16_icon_ ? k16x16IconTrailingSpacing : 0; | 292 const int label_y = LocationBarView::kNormalEdgeThickness; |
339 int host_label_width = | 293 const int label_height = height() - 2 * LocationBarView::kNormalEdgeThickness; |
340 width() - host_label_x - kEdgeThickness - kTrailingLabelMargin; | 294 if (ev_label_->visible()) { |
341 host_label_->SetBounds(host_label_x, | 295 int ev_label_width = |
342 LocationBarView::kNormalEdgeThickness, | 296 std::min(ev_label_->GetPreferredSize().width(), label_width); |
343 host_label_width, | 297 ev_label_->SetBounds(label_x, label_y, ev_label_width, label_height); |
344 height() - 2 * LocationBarView::kNormalEdgeThickness); | 298 // TODO(pkasting): See comments in GetPreferredSize(). |
299 ev_label_width += | |
300 gfx::GetStringWidth(base::ASCIIToUTF16(" "), GetFontList()); | |
301 label_x += ev_label_width; | |
302 label_width = std::max(0, label_width - ev_label_width); | |
303 } | |
304 host_label_->SetBounds(label_x, label_y, label_width, label_height); | |
305 } | |
306 | |
307 int OriginChipView::GetLabelX() const { | |
308 const int icon_spacing = showing_16x16_icon_ ? | |
309 (k16x16IconLeadingSpacing + k16x16IconTrailingSpacing) : 0; | |
310 return kEdgeThickness + location_icon_view_->GetPreferredSize().width() + | |
311 icon_spacing + kIconTextSpacing; | |
312 } | |
313 | |
314 void OriginChipView::SetBorderImages(const int images[3][9]) { | |
315 scoped_ptr<views::LabelButtonBorder> border( | |
316 new views::LabelButtonBorder(views::Button::STYLE_BUTTON)); | |
317 | |
318 for (size_t i = 0; i < 3; ++i) { | |
319 views::Painter* painter = views::Painter::CreateImageGridPainter(images[i]); | |
320 border->SetPainter(false, static_cast<Button::ButtonState>(i), painter); | |
321 | |
322 // Calculate a representative background color of the provided image grid to | |
323 // use as the background color of the host label in order to color the text | |
324 // appropriately. We grab the color of the middle pixel of the middle image | |
325 // of the background, which we treat as the representative color of the | |
326 // entire background (reasonable, given the current appearance of these | |
327 // images). | |
328 const SkBitmap& bitmap( | |
329 GetThemeProvider()->GetImageSkiaNamed( | |
330 images[i][4])->GetRepresentation(1.0f).sk_bitmap()); | |
331 SkAutoLockPixels pixel_lock(bitmap); | |
332 background_colors_[i] = | |
333 bitmap.getColor(bitmap.width() / 2, bitmap.height() / 2); | |
334 } | |
335 | |
336 // Calculate the actual text color of the pressed label. | |
337 host_label_->SetBackgroundColor(background_colors_[Button::STATE_PRESSED]); | |
338 pressed_text_color_ = host_label_->enabled_color(); | |
339 host_label_->SetBackgroundColor(background_colors_[state()]); | |
340 | |
341 SetBorder(border.PassAs<views::Border>()); | |
342 } | |
343 | |
344 void OriginChipView::AnimationProgressed(const gfx::Animation* animation) { | |
345 if (animation == &fade_in_animation_) | |
346 SchedulePaint(); | |
347 else | |
348 views::LabelButton::AnimationProgressed(animation); | |
349 } | |
350 | |
351 void OriginChipView::AnimationEnded(const gfx::Animation* animation) { | |
352 if (animation == &fade_in_animation_) | |
353 fade_in_animation_.Reset(); | |
354 else | |
355 views::LabelButton::AnimationEnded(animation); | |
345 } | 356 } |
346 | 357 |
347 void OriginChipView::OnPaintBorder(gfx::Canvas* canvas) { | 358 void OriginChipView::OnPaintBorder(gfx::Canvas* canvas) { |
348 if (fade_in_animation_->is_animating()) { | 359 if (fade_in_animation_.is_animating()) { |
349 canvas->SaveLayerAlpha(static_cast<uint8>( | 360 canvas->SaveLayerAlpha(static_cast<uint8>( |
350 fade_in_animation_->CurrentValueBetween(0, 255))); | 361 fade_in_animation_.CurrentValueBetween(0, 255))); |
351 views::LabelButton::OnPaintBorder(canvas); | 362 views::LabelButton::OnPaintBorder(canvas); |
352 canvas->Restore(); | 363 canvas->Restore(); |
353 } else { | 364 } else { |
354 views::LabelButton::OnPaintBorder(canvas); | 365 views::LabelButton::OnPaintBorder(canvas); |
355 } | 366 } |
356 } | 367 } |
357 | 368 |
369 void OriginChipView::StateChanged() { | |
370 DCHECK_LT(state(), 3); | |
371 SkColor background_color = background_colors_[state()]; | |
372 ev_label_->SetBackgroundColor(background_color); | |
373 host_label_->SetBackgroundColor(background_color); | |
374 } | |
375 | |
358 // TODO(gbillock): Make the LocationBarView or OmniboxView the listener for | 376 // TODO(gbillock): Make the LocationBarView or OmniboxView the listener for |
359 // this button. | 377 // this button. |
360 void OriginChipView::ButtonPressed(views::Button* sender, | 378 void OriginChipView::ButtonPressed(views::Button* sender, |
361 const ui::Event& event) { | 379 const ui::Event& event) { |
362 // See if the event needs to be passed to the LocationIconView. | 380 // See if the event needs to be passed to the LocationIconView. |
363 if (event.IsMouseEvent() || (event.type() == ui::ET_GESTURE_TAP)) { | 381 if (event.IsMouseEvent() || (event.type() == ui::ET_GESTURE_TAP)) { |
364 location_icon_view_->set_interactive(true); | 382 location_icon_view_->set_interactive(true); |
365 const ui::LocatedEvent& located_event = | 383 const ui::LocatedEvent& located_event = |
366 static_cast<const ui::LocatedEvent&>(event); | 384 static_cast<const ui::LocatedEvent&>(event); |
367 if (GetEventHandlerForPoint(located_event.location()) == | 385 if (GetEventHandlerForPoint(located_event.location()) == |
(...skipping 13 matching lines...) Expand all Loading... | |
381 | 399 |
382 // Note: When OnSafeBrowsingHit would be called, OnSafeBrowsingMatch will | 400 // Note: When OnSafeBrowsingHit would be called, OnSafeBrowsingMatch will |
383 // have already been called. | 401 // have already been called. |
384 void OriginChipView::OnSafeBrowsingHit( | 402 void OriginChipView::OnSafeBrowsingHit( |
385 const SafeBrowsingUIManager::UnsafeResource& resource) {} | 403 const SafeBrowsingUIManager::UnsafeResource& resource) {} |
386 | 404 |
387 void OriginChipView::OnSafeBrowsingMatch( | 405 void OriginChipView::OnSafeBrowsingMatch( |
388 const SafeBrowsingUIManager::UnsafeResource& resource) { | 406 const SafeBrowsingUIManager::UnsafeResource& resource) { |
389 OnChanged(); | 407 OnChanged(); |
390 } | 408 } |
OLD | NEW |