OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/toolbar/site_chip_view.h" | 5 #include "chrome/browser/ui/views/toolbar/site_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/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/extensions/extension_icon_image.h" | 13 #include "chrome/browser/extensions/extension_icon_image.h" |
14 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
15 #include "chrome/browser/favicon/favicon_tab_helper.h" | 15 #include "chrome/browser/favicon/favicon_tab_helper.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/safe_browsing/client_side_detection_host.h" | 17 #include "chrome/browser/safe_browsing/client_side_detection_host.h" |
18 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 18 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
19 #include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h" | 19 #include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h" |
20 #include "chrome/browser/safe_browsing/ui_manager.h" | 20 #include "chrome/browser/safe_browsing/ui_manager.h" |
21 #include "chrome/browser/search/search.h" | 21 #include "chrome/browser/search/search.h" |
22 #include "chrome/browser/themes/theme_properties.h" | 22 #include "chrome/browser/themes/theme_properties.h" |
23 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
24 #include "chrome/browser/ui/elide_url.h" | |
24 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 25 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
25 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 26 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
26 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 27 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
27 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 28 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
28 #include "chrome/common/extensions/extension_constants.h" | 29 #include "chrome/common/extensions/extension_constants.h" |
29 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" | 30 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" |
30 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
31 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
32 #include "content/public/browser/navigation_controller.h" | 33 #include "content/public/browser/navigation_controller.h" |
33 #include "content/public/browser/navigation_entry.h" | 34 #include "content/public/browser/navigation_entry.h" |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
359 base::string16 host = SiteLabelFromURL(url_displayed_); | 360 base::string16 host = SiteLabelFromURL(url_displayed_); |
360 if (security_level_ == ToolbarModel::EV_SECURE) { | 361 if (security_level_ == ToolbarModel::EV_SECURE) { |
361 host = l10n_util::GetStringFUTF16(IDS_SITE_CHIP_EV_SSL_LABEL, | 362 host = l10n_util::GetStringFUTF16(IDS_SITE_CHIP_EV_SSL_LABEL, |
362 toolbar_view_->GetToolbarModel()->GetEVCertName(), | 363 toolbar_view_->GetToolbarModel()->GetEVCertName(), |
363 host); | 364 host); |
364 } | 365 } |
365 | 366 |
366 host_label_->SetText(host); | 367 host_label_->SetText(host); |
367 host_label_->SetTooltipText(host); | 368 host_label_->SetTooltipText(host); |
368 host_label_->SetBackgroundColor(label_background); | 369 host_label_->SetBackgroundColor(label_background); |
370 host_label_->SetElideBehavior(views::Label::NO_ELIDE); | |
369 | 371 |
370 int icon = toolbar_view_->GetToolbarModel()->GetIconForSecurityLevel( | 372 int icon = toolbar_view_->GetToolbarModel()->GetIconForSecurityLevel( |
371 security_level_); | 373 security_level_); |
372 showing_16x16_icon_ = false; | 374 showing_16x16_icon_ = false; |
373 | 375 |
374 if (url_displayed_.is_empty() || | 376 if (url_displayed_.is_empty() || |
375 url_displayed_.SchemeIs(chrome::kChromeUIScheme)) { | 377 url_displayed_.SchemeIs(chrome::kChromeUIScheme)) { |
376 icon = IDR_PRODUCT_LOGO_16; | 378 icon = IDR_PRODUCT_LOGO_16; |
377 showing_16x16_icon_ = true; | 379 showing_16x16_icon_ = true; |
378 } | 380 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
442 } | 444 } |
443 | 445 |
444 void SiteChipView::OnPaint(gfx::Canvas* canvas) { | 446 void SiteChipView::OnPaint(gfx::Canvas* canvas) { |
445 gfx::Rect rect(GetLocalBounds()); | 447 gfx::Rect rect(GetLocalBounds()); |
446 if (painter_) | 448 if (painter_) |
447 views::Painter::PaintPainterAt(canvas, painter_, rect); | 449 views::Painter::PaintPainterAt(canvas, painter_, rect); |
448 | 450 |
449 ToolbarButton::OnPaint(canvas); | 451 ToolbarButton::OnPaint(canvas); |
450 } | 452 } |
451 | 453 |
454 int SiteChipView::ElideDomainTarget(int target_max_width) { | |
455 base::string16 host = SiteLabelFromURL(url_displayed_); | |
456 host_label_->SetText(host); | |
457 int width = GetPreferredSize().width(); | |
458 if (width <= target_max_width) | |
459 return width; | |
460 | |
461 gfx::Size label_size = host_label_->GetPreferredSize(); | |
462 int padding_width = width - label_size.width(); | |
463 | |
464 base::string16 elided_host = ElideHost( | |
Peter Kasting
2014/02/05 00:42:49
What is ElideHost() a reference to?
Nit: I'd just
Greg Billock
2014/02/05 18:32:05
This is the new functionality I've placed in the t
Peter Kasting
2014/02/05 21:08:08
OK. I don't know that I'm hugely keen on it being
Greg Billock
2014/02/06 17:38:51
It shares a great deal of code with ElideUrl, as y
| |
465 toolbar_view_->GetToolbarModel()->GetURL(), | |
466 host_label_->font_list(), target_max_width - padding_width); | |
467 host_label_->SetText(elided_host); | |
468 return GetPreferredSize().width(); | |
469 } | |
470 | |
452 // TODO(gbillock): Make the LocationBarView or OmniboxView the listener for | 471 // TODO(gbillock): Make the LocationBarView or OmniboxView the listener for |
453 // this button. | 472 // this button. |
454 void SiteChipView::ButtonPressed(views::Button* sender, | 473 void SiteChipView::ButtonPressed(views::Button* sender, |
455 const ui::Event& event) { | 474 const ui::Event& event) { |
456 // See if the event needs to be passed to the LocationIconView. | 475 // See if the event needs to be passed to the LocationIconView. |
457 if (event.IsMouseEvent() || (event.type() == ui::ET_GESTURE_TAP)) { | 476 if (event.IsMouseEvent() || (event.type() == ui::ET_GESTURE_TAP)) { |
458 location_icon_view_->set_interactive(true); | 477 location_icon_view_->set_interactive(true); |
459 const ui::LocatedEvent& located_event = | 478 const ui::LocatedEvent& located_event = |
460 static_cast<const ui::LocatedEvent&>(event); | 479 static_cast<const ui::LocatedEvent&>(event); |
461 if (GetEventHandlerForPoint(located_event.location()) == | 480 if (GetEventHandlerForPoint(located_event.location()) == |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
505 | 524 |
506 // Note: When OnSafeBrowsingHit would be called, OnSafeBrowsingMatch will | 525 // Note: When OnSafeBrowsingHit would be called, OnSafeBrowsingMatch will |
507 // have already been called. | 526 // have already been called. |
508 void SiteChipView::OnSafeBrowsingHit( | 527 void SiteChipView::OnSafeBrowsingHit( |
509 const SafeBrowsingUIManager::UnsafeResource& resource) {} | 528 const SafeBrowsingUIManager::UnsafeResource& resource) {} |
510 | 529 |
511 void SiteChipView::OnSafeBrowsingMatch( | 530 void SiteChipView::OnSafeBrowsingMatch( |
512 const SafeBrowsingUIManager::UnsafeResource& resource) { | 531 const SafeBrowsingUIManager::UnsafeResource& resource) { |
513 OnChanged(); | 532 OnChanged(); |
514 } | 533 } |
OLD | NEW |