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" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/extensions/extension_icon_image.h" | 12 #include "chrome/browser/extensions/extension_icon_image.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/favicon/favicon_tab_helper.h" | 14 #include "chrome/browser/favicon/favicon_tab_helper.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 16 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
17 #include "chrome/browser/safe_browsing/ui_manager.h" | 17 #include "chrome/browser/safe_browsing/ui_manager.h" |
18 #include "chrome/browser/search/search.h" | 18 #include "chrome/browser/search/search.h" |
19 #include "chrome/browser/themes/theme_properties.h" | 19 #include "chrome/browser/themes/theme_properties.h" |
20 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
21 #include "chrome/browser/ui/elide_url.h" | 21 #include "chrome/browser/ui/elide_url.h" |
22 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 22 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
23 #include "chrome/browser/ui/toolbar/origin_chip_info.h" | 23 #include "chrome/browser/ui/toolbar/origin_chip_info.h" |
24 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 24 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
25 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 25 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
26 #include "chrome/common/extensions/extension_constants.h" | 26 #include "chrome/common/extensions/extension_constants.h" |
27 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" | 27 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" |
28 #include "content/public/browser/navigation_controller.h" | |
29 #include "content/public/browser/navigation_entry.h" | |
30 #include "content/public/browser/user_metrics.h" | 28 #include "content/public/browser/user_metrics.h" |
31 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
32 #include "content/public/common/url_constants.h" | 30 #include "content/public/common/url_constants.h" |
33 #include "extensions/browser/extension_system.h" | 31 #include "extensions/browser/extension_system.h" |
34 #include "extensions/common/constants.h" | 32 #include "extensions/common/constants.h" |
35 #include "grit/generated_resources.h" | 33 #include "grit/generated_resources.h" |
36 #include "grit/theme_resources.h" | 34 #include "grit/theme_resources.h" |
37 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
38 #include "ui/base/resource/resource_bundle.h" | 36 #include "ui/base/resource/resource_bundle.h" |
39 #include "ui/base/theme_provider.h" | 37 #include "ui/base/theme_provider.h" |
| 38 #include "ui/gfx/animation/slide_animation.h" |
| 39 #include "ui/gfx/canvas.h" |
40 #include "ui/gfx/font_list.h" | 40 #include "ui/gfx/font_list.h" |
41 #include "ui/views/background.h" | 41 #include "ui/views/background.h" |
42 #include "ui/views/controls/button/label_button.h" | 42 #include "ui/views/controls/button/label_button.h" |
43 #include "ui/views/controls/button/label_button_border.h" | 43 #include "ui/views/controls/button/label_button_border.h" |
44 #include "ui/views/painter.h" | 44 #include "ui/views/painter.h" |
45 | 45 |
46 | 46 |
47 // OriginChipExtensionIcon ---------------------------------------------------- | 47 // OriginChipExtensionIcon ---------------------------------------------------- |
48 | 48 |
49 class OriginChipExtensionIcon : public extensions::IconImage::Observer { | 49 class OriginChipExtensionIcon : public extensions::IconImage::Observer { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 | 157 |
158 // TODO(gbillock): Would be nice to just use stock LabelButton stuff here. | 158 // TODO(gbillock): Would be nice to just use stock LabelButton stuff here. |
159 location_icon_view_ = new LocationIconView(location_bar_view_); | 159 location_icon_view_ = new LocationIconView(location_bar_view_); |
160 // Make location icon hover events count as hovering the origin chip. | 160 // Make location icon hover events count as hovering the origin chip. |
161 location_icon_view_->set_interactive(false); | 161 location_icon_view_->set_interactive(false); |
162 location_icon_view_->ShowTooltip(true); | 162 location_icon_view_->ShowTooltip(true); |
163 AddChildView(location_icon_view_); | 163 AddChildView(location_icon_view_); |
164 | 164 |
165 host_label_ = new views::Label(base::string16(), GetFontList()); | 165 host_label_ = new views::Label(base::string16(), GetFontList()); |
166 AddChildView(host_label_); | 166 AddChildView(host_label_); |
| 167 |
| 168 fade_in_animation_.reset(new gfx::SlideAnimation(this)); |
| 169 fade_in_animation_->SetTweenType(gfx::Tween::LINEAR); |
| 170 fade_in_animation_->SetSlideDuration(300); |
167 } | 171 } |
168 | 172 |
169 bool OriginChipView::ShouldShow() { | 173 bool OriginChipView::ShouldShow() { |
170 return chrome::ShouldDisplayOriginChipV2() && | 174 return chrome::ShouldDisplayOriginChipV2() && |
171 location_bar_view_->GetToolbarModel()->WouldOmitURLDueToOriginChip() && | 175 location_bar_view_->GetToolbarModel()->WouldOmitURLDueToOriginChip() && |
172 location_bar_view_->GetToolbarModel()->origin_chip_enabled(); | 176 location_bar_view_->GetToolbarModel()->origin_chip_enabled(); |
173 } | 177 } |
174 | 178 |
175 void OriginChipView::Update(content::WebContents* web_contents) { | 179 void OriginChipView::Update(content::WebContents* web_contents) { |
176 if (!web_contents) | 180 if (!web_contents) |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 host_label_->SetBackgroundColor( | 277 host_label_->SetBackgroundColor( |
274 bitmap.getColor(bitmap.width() / 2, bitmap.height() / 2)); | 278 bitmap.getColor(bitmap.width() / 2, bitmap.height() / 2)); |
275 } | 279 } |
276 | 280 |
277 void OriginChipView::OnChanged() { | 281 void OriginChipView::OnChanged() { |
278 Update(location_bar_view_->GetWebContents()); | 282 Update(location_bar_view_->GetWebContents()); |
279 // TODO(gbillock): Also need to potentially repaint infobars to make sure the | 283 // TODO(gbillock): Also need to potentially repaint infobars to make sure the |
280 // arrows are pointing to the right spot. Only needed for some edge cases. | 284 // arrows are pointing to the right spot. Only needed for some edge cases. |
281 } | 285 } |
282 | 286 |
| 287 void OriginChipView::FadeIn() { |
| 288 fade_in_animation_->Show(); |
| 289 } |
| 290 |
| 291 int OriginChipView::LabelPosition() { |
| 292 return host_label_->x(); |
| 293 } |
| 294 |
| 295 void OriginChipView::AnimationProgressed(const gfx::Animation* animation) { |
| 296 if (animation == fade_in_animation_.get()) { |
| 297 SchedulePaint(); |
| 298 } else { |
| 299 views::LabelButton::AnimationProgressed(animation); |
| 300 } |
| 301 } |
| 302 |
| 303 void OriginChipView::AnimationEnded(const gfx::Animation* animation) { |
| 304 if (animation == fade_in_animation_.get()) { |
| 305 fade_in_animation_->Reset(); |
| 306 } else { |
| 307 views::LabelButton::AnimationEnded(animation); |
| 308 } |
| 309 } |
| 310 |
283 gfx::Size OriginChipView::GetPreferredSize() { | 311 gfx::Size OriginChipView::GetPreferredSize() { |
284 gfx::Size label_size = host_label_->GetPreferredSize(); | 312 gfx::Size label_size = host_label_->GetPreferredSize(); |
285 gfx::Size icon_size = location_icon_view_->GetPreferredSize(); | 313 gfx::Size icon_size = location_icon_view_->GetPreferredSize(); |
286 int icon_spacing = showing_16x16_icon_ ? | 314 int icon_spacing = showing_16x16_icon_ ? |
287 (k16x16IconLeadingSpacing + k16x16IconTrailingSpacing) : 0; | 315 (k16x16IconLeadingSpacing + k16x16IconTrailingSpacing) : 0; |
288 return gfx::Size(kEdgeThickness + icon_size.width() + icon_spacing + | 316 return gfx::Size(kEdgeThickness + icon_size.width() + icon_spacing + |
289 kIconTextSpacing + label_size.width() + | 317 kIconTextSpacing + label_size.width() + |
290 kTrailingLabelMargin + kEdgeThickness, | 318 kTrailingLabelMargin + kEdgeThickness, |
291 icon_size.height()); | 319 icon_size.height()); |
292 } | 320 } |
(...skipping 12 matching lines...) Expand all Loading... |
305 kIconTextSpacing; | 333 kIconTextSpacing; |
306 host_label_x += showing_16x16_icon_ ? k16x16IconTrailingSpacing : 0; | 334 host_label_x += showing_16x16_icon_ ? k16x16IconTrailingSpacing : 0; |
307 int host_label_width = | 335 int host_label_width = |
308 width() - host_label_x - kEdgeThickness - kTrailingLabelMargin; | 336 width() - host_label_x - kEdgeThickness - kTrailingLabelMargin; |
309 host_label_->SetBounds(host_label_x, | 337 host_label_->SetBounds(host_label_x, |
310 LocationBarView::kNormalEdgeThickness, | 338 LocationBarView::kNormalEdgeThickness, |
311 host_label_width, | 339 host_label_width, |
312 height() - 2 * LocationBarView::kNormalEdgeThickness); | 340 height() - 2 * LocationBarView::kNormalEdgeThickness); |
313 } | 341 } |
314 | 342 |
| 343 void OriginChipView::OnPaintBorder(gfx::Canvas* canvas) { |
| 344 if (fade_in_animation_->is_animating()) { |
| 345 canvas->SaveLayerAlpha(static_cast<uint8>( |
| 346 fade_in_animation_->CurrentValueBetween(0, 255))); |
| 347 views::LabelButton::OnPaintBorder(canvas); |
| 348 canvas->Restore(); |
| 349 } else { |
| 350 views::LabelButton::OnPaintBorder(canvas); |
| 351 } |
| 352 } |
| 353 |
315 int OriginChipView::ElideDomainTarget(int target_max_width) { | 354 int OriginChipView::ElideDomainTarget(int target_max_width) { |
316 base::string16 host = | 355 base::string16 host = |
317 OriginChip::LabelFromURLForProfile(url_displayed_, profile_); | 356 OriginChip::LabelFromURLForProfile(url_displayed_, profile_); |
318 host_label_->SetText(host); | 357 host_label_->SetText(host); |
319 int width = GetPreferredSize().width(); | 358 int width = GetPreferredSize().width(); |
320 if (width <= target_max_width) | 359 if (width <= target_max_width) |
321 return width; | 360 return width; |
322 | 361 |
323 gfx::Size label_size = host_label_->GetPreferredSize(); | 362 gfx::Size label_size = host_label_->GetPreferredSize(); |
324 int padding_width = width - label_size.width(); | 363 int padding_width = width - label_size.width(); |
(...skipping 18 matching lines...) Expand all Loading... |
343 location_icon_view_->page_info_helper()->ProcessEvent(located_event); | 382 location_icon_view_->page_info_helper()->ProcessEvent(located_event); |
344 location_icon_view_->set_interactive(false); | 383 location_icon_view_->set_interactive(false); |
345 return; | 384 return; |
346 } | 385 } |
347 location_icon_view_->set_interactive(false); | 386 location_icon_view_->set_interactive(false); |
348 } | 387 } |
349 | 388 |
350 UMA_HISTOGRAM_COUNTS("OriginChip.Pressed", 1); | 389 UMA_HISTOGRAM_COUNTS("OriginChip.Pressed", 1); |
351 content::RecordAction(base::UserMetricsAction("OriginChipPress")); | 390 content::RecordAction(base::UserMetricsAction("OriginChipPress")); |
352 | 391 |
353 location_bar_view_->GetOmniboxView()->ShowURL(); | 392 location_bar_view_->ShowURL(); |
354 } | 393 } |
355 | 394 |
356 // Note: When OnSafeBrowsingHit would be called, OnSafeBrowsingMatch will | 395 // Note: When OnSafeBrowsingHit would be called, OnSafeBrowsingMatch will |
357 // have already been called. | 396 // have already been called. |
358 void OriginChipView::OnSafeBrowsingHit( | 397 void OriginChipView::OnSafeBrowsingHit( |
359 const SafeBrowsingUIManager::UnsafeResource& resource) {} | 398 const SafeBrowsingUIManager::UnsafeResource& resource) {} |
360 | 399 |
361 void OriginChipView::OnSafeBrowsingMatch( | 400 void OriginChipView::OnSafeBrowsingMatch( |
362 const SafeBrowsingUIManager::UnsafeResource& resource) { | 401 const SafeBrowsingUIManager::UnsafeResource& resource) { |
363 OnChanged(); | 402 OnChanged(); |
364 } | 403 } |
OLD | NEW |