Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: chrome/browser/ui/views/location_bar/location_bar_view.cc

Issue 2144903004: New location security strings and animation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <iostream>
8 #include <map> 9 #include <map>
9 10
10 #include "base/i18n/rtl.h" 11 #include "base/i18n/rtl.h"
11 #include "base/stl_util.h" 12 #include "base/stl_util.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
13 #include "build/build_config.h" 14 #include "build/build_config.h"
14 #include "chrome/app/chrome_command_ids.h" 15 #include "chrome/app/chrome_command_ids.h"
15 #include "chrome/browser/command_updater.h" 16 #include "chrome/browser/command_updater.h"
16 #include "chrome/browser/defaults.h" 17 #include "chrome/browser/defaults.h"
17 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" 18 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h"
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 DCHECK(page_action); 385 DCHECK(page_action);
385 WebContents* web_contents = GetWebContents(); 386 WebContents* web_contents = GetWebContents();
386 387
387 RefreshPageActionViews(); 388 RefreshPageActionViews();
388 PageActionWithBadgeView* page_action_view = 389 PageActionWithBadgeView* page_action_view =
389 static_cast<PageActionWithBadgeView*>(GetPageActionView(page_action)); 390 static_cast<PageActionWithBadgeView*>(GetPageActionView(page_action));
390 DCHECK(page_action_view); 391 DCHECK(page_action_view);
391 if (!page_action_view) 392 if (!page_action_view)
392 return; 393 return;
393 394
395 // Tell the location icon to animate here?
Peter Kasting 2016/07/19 21:17:20 Why? This function is all about mucking with a sp
Kevin Bailey 2016/08/12 18:49:14 ack
396
394 page_action_view->image_view()->set_preview_enabled(preview_enabled); 397 page_action_view->image_view()->set_preview_enabled(preview_enabled);
395 page_action_view->UpdateVisibility(web_contents); 398 page_action_view->UpdateVisibility(web_contents);
396 Layout(); 399 Layout();
397 SchedulePaint(); 400 SchedulePaint();
398 } 401 }
399 402
400 PageActionWithBadgeView* LocationBarView::GetPageActionView( 403 PageActionWithBadgeView* LocationBarView::GetPageActionView(
401 ExtensionAction* page_action) { 404 ExtensionAction* page_action) {
402 DCHECK(page_action); 405 DCHECK(page_action);
403 for (PageActionViews::const_iterator i(page_action_views_.begin()); 406 for (PageActionViews::const_iterator i(page_action_views_.begin());
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 528
526 min_size.set_height(min_size.height() * size_animation_.GetCurrentValue()); 529 min_size.set_height(min_size.height() * size_animation_.GetCurrentValue());
527 530
528 const int padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); 531 const int padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING);
529 532
530 // Compute width of omnibox-leading content. 533 // Compute width of omnibox-leading content.
531 const int edge_thickness = GetHorizontalEdgeThickness(); 534 const int edge_thickness = GetHorizontalEdgeThickness();
532 int leading_width = edge_thickness; 535 int leading_width = edge_thickness;
533 if (ShouldShowKeywordBubble()) { 536 if (ShouldShowKeywordBubble()) {
534 // The selected keyword view can collapse completely. 537 // The selected keyword view can collapse completely.
535 } else if (ShouldShowEVBubble()) { 538 } else if (ShouldShowSecureVerbose()) {
539 base::string16 label = ShouldShowEVBubble()
540 ? GetToolbarModel()->GetEVCertName()
541 : GetToolbarModel()->GetSecureVerboseText();
Peter Kasting 2016/07/19 21:17:20 Nit: Could factor GetToolbarModel() out. And sinc
Kevin Bailey 2016/08/12 18:49:14 Done.
536 leading_width += GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING) + 542 leading_width += GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING) +
537 location_icon_view_->GetMinimumSizeForLabelText( 543 location_icon_view_->GetMinimumSizeForLabelText(label)
538 GetToolbarModel()->GetEVCertName())
539 .width(); 544 .width();
540 } else { 545 } else {
541 leading_width += padding + location_icon_view_->GetMinimumSize().width(); 546 leading_width += padding + location_icon_view_->GetMinimumSize().width();
542 } 547 }
543 548
544 // Compute width of omnibox-trailing content. 549 // Compute width of omnibox-trailing content.
545 int trailing_width = edge_thickness; 550 int trailing_width = edge_thickness;
546 trailing_width += IncrementalMinimumWidth(star_view_) + 551 trailing_width += IncrementalMinimumWidth(star_view_) +
547 IncrementalMinimumWidth(translate_icon_view_) + 552 IncrementalMinimumWidth(translate_icon_view_) +
548 IncrementalMinimumWidth(open_pdf_in_reader_view_) + 553 IncrementalMinimumWidth(open_pdf_in_reader_view_) +
549 IncrementalMinimumWidth(save_credit_card_icon_view_) + 554 IncrementalMinimumWidth(save_credit_card_icon_view_) +
550 IncrementalMinimumWidth(manage_passwords_icon_view_) + 555 IncrementalMinimumWidth(manage_passwords_icon_view_) +
551 IncrementalMinimumWidth(zoom_view_); 556 IncrementalMinimumWidth(zoom_view_);
552 for (PageActionViews::const_iterator i(page_action_views_.begin()); 557 for (PageActionViews::const_iterator i(page_action_views_.begin());
553 i != page_action_views_.end(); ++i) 558 i != page_action_views_.end(); ++i)
554 trailing_width += IncrementalMinimumWidth((*i)); 559 trailing_width += IncrementalMinimumWidth((*i));
555 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); 560 for (ContentSettingViews::const_iterator i(content_setting_views_.begin());
556 i != content_setting_views_.end(); ++i) 561 i != content_setting_views_.end(); ++i)
557 trailing_width += IncrementalMinimumWidth((*i)); 562 trailing_width += IncrementalMinimumWidth((*i));
558 563
559 min_size.set_width(leading_width + omnibox_view_->GetMinimumSize().width() + 564 min_size.set_width(leading_width + omnibox_view_->GetMinimumSize().width() +
560 2 * padding - omnibox_view_->GetInsets().width() + 565 2 * padding - omnibox_view_->GetInsets().width() +
561 trailing_width); 566 trailing_width);
562 return min_size; 567 return min_size;
563 } 568 }
564 569
565 void LocationBarView::Layout() { 570 void LocationBarView::Layout() {
571 std::cout << "LocationBar::Layout " << (void*)this << "\n";
566 if (!IsInitialized()) 572 if (!IsInitialized())
567 return; 573 return;
568 574
569 selected_keyword_view_->SetVisible(false); 575 selected_keyword_view_->SetVisible(false);
570 location_icon_view_->SetVisible(false); 576 location_icon_view_->SetVisible(false);
571 keyword_hint_view_->SetVisible(false); 577 keyword_hint_view_->SetVisible(false);
572 578
573 const int item_padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); 579 const int item_padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING);
574 const int edge_thickness = GetHorizontalEdgeThickness(); 580 const int edge_thickness = GetHorizontalEdgeThickness();
575 581
(...skipping 29 matching lines...) Expand all
605 (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) { 611 (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) {
606 gfx::Image image = extensions::OmniboxAPI::Get(profile())-> 612 gfx::Image image = extensions::OmniboxAPI::Get(profile())->
607 GetOmniboxIcon(template_url->GetExtensionId()); 613 GetOmniboxIcon(template_url->GetExtensionId());
608 selected_keyword_view_->SetImage(image.AsImageSkia()); 614 selected_keyword_view_->SetImage(image.AsImageSkia());
609 selected_keyword_view_->set_is_extension_icon(true); 615 selected_keyword_view_->set_is_extension_icon(true);
610 } else { 616 } else {
611 selected_keyword_view_->ResetImage(); 617 selected_keyword_view_->ResetImage();
612 selected_keyword_view_->set_is_extension_icon(false); 618 selected_keyword_view_->set_is_extension_icon(false);
613 } 619 }
614 } 620 }
615 } else if (ShouldShowEVBubble()) { 621 } else if (ShouldShowSecureVerbose()) {
616 location_icon_view_->SetLabel(GetToolbarModel()->GetEVCertName()); 622 location_icon_view_->SetLabel(ShouldShowEVBubble()
623 ? GetToolbarModel()->GetEVCertName()
624 : GetToolbarModel()->GetSecureVerboseText());
617 location_icon_view_->SetBackground(true); 625 location_icon_view_->SetBackground(true);
626 // Not necessarily the best place, and shouldn't be done unconditionally.
627 location_icon_view_->StartAnimation();
Peter Kasting 2016/07/19 21:17:20 Yeah, definitely don't do this from layout, that c
Kevin Bailey 2016/08/12 18:49:14 It turns out to be quite useful to do this here. I
618 // The largest fraction of the omnibox that can be taken by the EV bubble. 628 // The largest fraction of the omnibox that can be taken by the EV bubble.
619 const double kMaxBubbleFraction = 0.5; 629 const double kMaxBubbleFraction = 0.5;
620 leading_decorations.AddDecoration( 630 leading_decorations.AddDecoration(
621 vertical_padding, location_height, false, kMaxBubbleFraction, 631 vertical_padding, location_height, false, kMaxBubbleFraction,
622 bubble_horizontal_padding, item_padding, location_icon_view_); 632 bubble_horizontal_padding, item_padding, location_icon_view_);
623 } else { 633 } else {
624 leading_decorations.AddDecoration(vertical_padding, location_height, 634 leading_decorations.AddDecoration(vertical_padding, location_height,
625 location_icon_view_); 635 location_icon_view_);
626 } 636 }
627 637
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 void LocationBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) { 786 void LocationBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) {
777 if (ui::MaterialDesignController::IsModeMaterial()) { 787 if (ui::MaterialDesignController::IsModeMaterial()) {
778 RefreshLocationIcon(); 788 RefreshLocationIcon();
779 if (!is_popup_mode_) { 789 if (!is_popup_mode_) {
780 set_background(new BackgroundWith1PxBorder(GetColor(BACKGROUND), 790 set_background(new BackgroundWith1PxBorder(GetColor(BACKGROUND),
781 kBorderColor)); 791 kBorderColor));
782 } 792 }
783 } 793 }
784 } 794 }
785 795
796 // Called twice per page visit. 'contents' never set.
Peter Kasting 2016/07/19 21:17:20 That's because |contents| is set when switching ta
Kevin Bailey 2016/08/12 18:49:14 I only see it set on the very first page load. Str
797 // Still looking for what's called once.
Peter Kasting 2016/07/19 21:17:20 I'm not sure there is anything. Update() is proba
Kevin Bailey 2016/08/12 18:49:14 ack
786 void LocationBarView::Update(const WebContents* contents) { 798 void LocationBarView::Update(const WebContents* contents) {
787 RefreshContentSettingViews(); 799 RefreshContentSettingViews();
788 RefreshZoomView(); 800 RefreshZoomView();
789 RefreshPageActionViews(); 801 RefreshPageActionViews();
790 RefreshTranslateIcon(); 802 RefreshTranslateIcon();
791 RefreshSaveCreditCardIconView(); 803 RefreshSaveCreditCardIconView();
792 RefreshManagePasswordsIconView(); 804 RefreshManagePasswordsIconView();
793 content::WebContents* web_contents_for_sub_views = 805 content::WebContents* web_contents_for_sub_views =
794 GetToolbarModel()->input_in_progress() ? nullptr : GetWebContents(); 806 GetToolbarModel()->input_in_progress() ? nullptr : GetWebContents();
795 open_pdf_in_reader_view_->Update(web_contents_for_sub_views); 807 open_pdf_in_reader_view_->Update(web_contents_for_sub_views);
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 return suggested_text_view_->visible() && 1049 return suggested_text_view_->visible() &&
1038 !suggested_text_view_->size().IsEmpty(); 1050 !suggested_text_view_->size().IsEmpty();
1039 } 1051 }
1040 1052
1041 bool LocationBarView::ShouldShowKeywordBubble() const { 1053 bool LocationBarView::ShouldShowKeywordBubble() const {
1042 return !omnibox_view_->model()->keyword().empty() && 1054 return !omnibox_view_->model()->keyword().empty() &&
1043 !omnibox_view_->model()->is_keyword_hint(); 1055 !omnibox_view_->model()->is_keyword_hint();
1044 } 1056 }
1045 1057
1046 bool LocationBarView::ShouldShowEVBubble() const { 1058 bool LocationBarView::ShouldShowEVBubble() const {
1059 std::cout << "EV level is " << GetToolbarModel()->GetSecurityLevel(false)
1060 << "\n";
1047 return (GetToolbarModel()->GetSecurityLevel(false) == 1061 return (GetToolbarModel()->GetSecurityLevel(false) ==
1048 security_state::SecurityStateModel::EV_SECURE); 1062 security_state::SecurityStateModel::EV_SECURE);
1049 } 1063 }
1050 1064
1065 bool LocationBarView::ShouldShowSecureVerbose() const {
1066 return ui::MaterialDesignController::IsModeMaterial() &&
Peter Kasting 2016/07/19 21:17:20 Why condition this on material mode?
Kevin Bailey 2016/08/12 18:49:14 Done.
1067 !omnibox_view_->IsEditingOrEmpty() &&
1068 !ShouldShowKeywordBubble() &&
1069 GetToolbarModel()->GetSecurityLevel(false) !=
1070 security_state::SecurityStateModel::NONE;
Peter Kasting 2016/07/19 21:17:20 I thought we wanted to be verbose about HTTP too?
Kevin Bailey 2016/08/12 18:49:14 Done.
1071 }
1072
1051 //////////////////////////////////////////////////////////////////////////////// 1073 ////////////////////////////////////////////////////////////////////////////////
1052 // LocationBarView, private LocationBar implementation: 1074 // LocationBarView, private LocationBar implementation:
1053 1075
1054 void LocationBarView::ShowFirstRunBubble() { 1076 void LocationBarView::ShowFirstRunBubble() {
1055 // Wait until search engines have loaded to show the first run bubble. 1077 // Wait until search engines have loaded to show the first run bubble.
1056 TemplateURLService* url_service = 1078 TemplateURLService* url_service =
1057 TemplateURLServiceFactory::GetForProfile(profile()); 1079 TemplateURLServiceFactory::GetForProfile(profile());
1058 if (!url_service->loaded()) { 1080 if (!url_service->loaded()) {
1059 template_url_service_ = url_service; 1081 template_url_service_ = url_service;
1060 template_url_service_->AddObserver(this); 1082 template_url_service_->AddObserver(this);
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 // LocationBarView, private TemplateURLServiceObserver implementation: 1407 // LocationBarView, private TemplateURLServiceObserver implementation:
1386 1408
1387 void LocationBarView::OnTemplateURLServiceChanged() { 1409 void LocationBarView::OnTemplateURLServiceChanged() {
1388 template_url_service_->RemoveObserver(this); 1410 template_url_service_->RemoveObserver(this);
1389 template_url_service_ = nullptr; 1411 template_url_service_ = nullptr;
1390 // If the browser is no longer active, let's not show the info bubble, as this 1412 // If the browser is no longer active, let's not show the info bubble, as this
1391 // would make the browser the active window again. 1413 // would make the browser the active window again.
1392 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) 1414 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive())
1393 ShowFirstRunBubble(); 1415 ShowFirstRunBubble();
1394 } 1416 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698