| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/location_bar_view.h" | 5 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 return min_size; | 489 return min_size; |
| 490 | 490 |
| 491 min_size.set_height(min_size.height() * size_animation_.GetCurrentValue()); | 491 min_size.set_height(min_size.height() * size_animation_.GetCurrentValue()); |
| 492 | 492 |
| 493 // Compute width of omnibox-leading content. | 493 // Compute width of omnibox-leading content. |
| 494 const int edge_thickness = GetHorizontalEdgeThickness(); | 494 const int edge_thickness = GetHorizontalEdgeThickness(); |
| 495 int leading_width = edge_thickness; | 495 int leading_width = edge_thickness; |
| 496 if (ShouldShowKeywordBubble()) { | 496 if (ShouldShowKeywordBubble()) { |
| 497 // The selected keyword view can collapse completely. | 497 // The selected keyword view can collapse completely. |
| 498 } else if (ShouldShowSecurityChip()) { | 498 } else if (ShouldShowSecurityChip()) { |
| 499 base::string16 security_text = GetSecurityText(); | 499 const base::string16 security_text = GetSecurityText(); |
| 500 leading_width += | 500 leading_width += |
| 501 location_icon_view_->GetMinimumSizeForLabelText(security_text).width(); | 501 location_icon_view_->GetMinimumSizeForLabelText(security_text).width(); |
| 502 } else if (ShouldShowExtensionChip()) { |
| 503 const base::string16 extension_name = GetExtensionName( |
| 504 GetToolbarModel()->GetURL(), delegate_->GetWebContents()); |
| 505 leading_width += |
| 506 location_icon_view_->GetMinimumSizeForLabelText(extension_name).width(); |
| 502 } else { | 507 } else { |
| 503 leading_width += | 508 leading_width += |
| 504 kHorizontalPadding + location_icon_view_->GetMinimumSize().width(); | 509 kHorizontalPadding + location_icon_view_->GetMinimumSize().width(); |
| 505 } | 510 } |
| 506 | 511 |
| 507 // Compute width of omnibox-trailing content. | 512 // Compute width of omnibox-trailing content. |
| 508 int trailing_width = edge_thickness; | 513 int trailing_width = edge_thickness; |
| 509 trailing_width += IncrementalMinimumWidth(star_view_) + | 514 trailing_width += IncrementalMinimumWidth(star_view_) + |
| 510 IncrementalMinimumWidth(translate_icon_view_) + | 515 IncrementalMinimumWidth(translate_icon_view_) + |
| 511 IncrementalMinimumWidth(open_pdf_in_reader_view_) + | 516 IncrementalMinimumWidth(open_pdf_in_reader_view_) + |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 GetTemplateURLForKeyword(keyword); | 567 GetTemplateURLForKeyword(keyword); |
| 563 if (template_url && | 568 if (template_url && |
| 564 (template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION)) { | 569 (template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION)) { |
| 565 gfx::Image image = extensions::OmniboxAPI::Get(profile())-> | 570 gfx::Image image = extensions::OmniboxAPI::Get(profile())-> |
| 566 GetOmniboxIcon(template_url->GetExtensionId()); | 571 GetOmniboxIcon(template_url->GetExtensionId()); |
| 567 selected_keyword_view_->SetImage(image.AsImageSkia()); | 572 selected_keyword_view_->SetImage(image.AsImageSkia()); |
| 568 } else { | 573 } else { |
| 569 selected_keyword_view_->ResetImage(); | 574 selected_keyword_view_->ResetImage(); |
| 570 } | 575 } |
| 571 } | 576 } |
| 577 } else if (ShouldShowExtensionChip()) { |
| 578 location_icon_view_->SetLabel(GetExtensionName( |
| 579 GetToolbarModel()->GetURL(), delegate_->GetWebContents())); |
| 580 const double kMaxBubbleFraction = 0.5; |
| 581 leading_decorations.AddDecoration(vertical_padding, location_height, false, |
| 582 kMaxBubbleFraction, 0, item_padding, |
| 583 location_icon_view_); |
| 572 } else if (ShouldShowSecurityChip()) { | 584 } else if (ShouldShowSecurityChip()) { |
| 573 location_icon_view_->SetLabel(GetSecurityText()); | 585 location_icon_view_->SetLabel(GetSecurityText()); |
| 574 // The largest fraction of the omnibox that can be taken by the EV bubble. | 586 // The largest fraction of the omnibox that can be taken by the EV bubble. |
| 575 const double kMaxBubbleFraction = 0.5; | 587 const double kMaxBubbleFraction = 0.5; |
| 576 leading_decorations.AddDecoration(vertical_padding, location_height, false, | 588 leading_decorations.AddDecoration(vertical_padding, location_height, false, |
| 577 kMaxBubbleFraction, 0, item_padding, | 589 kMaxBubbleFraction, 0, item_padding, |
| 578 location_icon_view_); | 590 location_icon_view_); |
| 579 } else { | 591 } else { |
| 580 leading_decorations.AddDecoration(vertical_padding, location_height, | 592 leading_decorations.AddDecoration(vertical_padding, location_height, |
| 581 location_icon_view_); | 593 location_icon_view_); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 open_pdf_in_reader_view_->Update(web_contents_for_sub_views); | 704 open_pdf_in_reader_view_->Update(web_contents_for_sub_views); |
| 693 | 705 |
| 694 if (star_view_) | 706 if (star_view_) |
| 695 UpdateBookmarkStarVisibility(); | 707 UpdateBookmarkStarVisibility(); |
| 696 | 708 |
| 697 if (contents) | 709 if (contents) |
| 698 omnibox_view_->OnTabChanged(contents); | 710 omnibox_view_->OnTabChanged(contents); |
| 699 else | 711 else |
| 700 omnibox_view_->Update(); | 712 omnibox_view_->Update(); |
| 701 | 713 |
| 702 location_icon_view_->SetSecurityState( | 714 location_icon_view_->SetDisplayState( |
| 703 ShouldShowSecurityChip(), !contents && ShouldAnimateSecurityChip()); | 715 ShouldShowSecurityChip() || ShouldShowExtensionChip(), |
| 704 | 716 !contents && ShouldAnimateSecurityChip()); |
| 705 OnChanged(); // NOTE: Calls Layout(). | 717 OnChanged(); // NOTE: Calls Layout(). |
| 706 } | 718 } |
| 707 | 719 |
| 708 void LocationBarView::ResetTabState(WebContents* contents) { | 720 void LocationBarView::ResetTabState(WebContents* contents) { |
| 709 omnibox_view_->ResetTabState(contents); | 721 omnibox_view_->ResetTabState(contents); |
| 710 } | 722 } |
| 711 | 723 |
| 712 //////////////////////////////////////////////////////////////////////////////// | 724 //////////////////////////////////////////////////////////////////////////////// |
| 713 // LocationBarView, public OmniboxEditController implementation: | 725 // LocationBarView, public OmniboxEditController implementation: |
| 714 | 726 |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 949 SecurityLevel level = GetToolbarModel()->GetSecurityLevel(false); | 961 SecurityLevel level = GetToolbarModel()->GetSecurityLevel(false); |
| 950 if (!ShouldShowSecurityChip()) | 962 if (!ShouldShowSecurityChip()) |
| 951 return false; | 963 return false; |
| 952 if (level == SecurityLevel::SECURE || level == SecurityLevel::EV_SECURE) | 964 if (level == SecurityLevel::SECURE || level == SecurityLevel::EV_SECURE) |
| 953 return should_animate_secure_state_; | 965 return should_animate_secure_state_; |
| 954 return should_animate_nonsecure_state_ && | 966 return should_animate_nonsecure_state_ && |
| 955 (level == SecurityLevel::DANGEROUS || | 967 (level == SecurityLevel::DANGEROUS || |
| 956 level == SecurityLevel::HTTP_SHOW_WARNING); | 968 level == SecurityLevel::HTTP_SHOW_WARNING); |
| 957 } | 969 } |
| 958 | 970 |
| 971 bool LocationBarView::ShouldShowExtensionChip() const { |
| 972 return GetToolbarModel()->GetURL().SchemeIs(extensions::kExtensionScheme); |
| 973 } |
| 974 |
| 959 //////////////////////////////////////////////////////////////////////////////// | 975 //////////////////////////////////////////////////////////////////////////////// |
| 960 // LocationBarView, private LocationBar implementation: | 976 // LocationBarView, private LocationBar implementation: |
| 961 | 977 |
| 962 void LocationBarView::ShowFirstRunBubble() { | 978 void LocationBarView::ShowFirstRunBubble() { |
| 963 // Wait until search engines have loaded to show the first run bubble. | 979 // Wait until search engines have loaded to show the first run bubble. |
| 964 TemplateURLService* url_service = | 980 TemplateURLService* url_service = |
| 965 TemplateURLServiceFactory::GetForProfile(profile()); | 981 TemplateURLServiceFactory::GetForProfile(profile()); |
| 966 if (!url_service->loaded()) { | 982 if (!url_service->loaded()) { |
| 967 template_url_service_ = url_service; | 983 template_url_service_ = url_service; |
| 968 template_url_service_->AddObserver(this); | 984 template_url_service_->AddObserver(this); |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1264 // LocationBarView, private TemplateURLServiceObserver implementation: | 1280 // LocationBarView, private TemplateURLServiceObserver implementation: |
| 1265 | 1281 |
| 1266 void LocationBarView::OnTemplateURLServiceChanged() { | 1282 void LocationBarView::OnTemplateURLServiceChanged() { |
| 1267 template_url_service_->RemoveObserver(this); | 1283 template_url_service_->RemoveObserver(this); |
| 1268 template_url_service_ = nullptr; | 1284 template_url_service_ = nullptr; |
| 1269 // If the browser is no longer active, let's not show the info bubble, as this | 1285 // If the browser is no longer active, let's not show the info bubble, as this |
| 1270 // would make the browser the active window again. | 1286 // would make the browser the active window again. |
| 1271 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) | 1287 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) |
| 1272 ShowFirstRunBubble(); | 1288 ShowFirstRunBubble(); |
| 1273 } | 1289 } |
| OLD | NEW |