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/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
319 return native_theme->GetSystemColor( | 319 return native_theme->GetSystemColor( |
320 ui::NativeTheme::kColorId_TextfieldDefaultColor); | 320 ui::NativeTheme::kColorId_TextfieldDefaultColor); |
321 | 321 |
322 case SELECTED_TEXT: | 322 case SELECTED_TEXT: |
323 return native_theme->GetSystemColor( | 323 return native_theme->GetSystemColor( |
324 ui::NativeTheme::kColorId_TextfieldSelectionColor); | 324 ui::NativeTheme::kColorId_TextfieldSelectionColor); |
325 | 325 |
326 case DEEMPHASIZED_TEXT: | 326 case DEEMPHASIZED_TEXT: |
327 return color_utils::AlphaBlend(GetColor(TEXT), GetColor(BACKGROUND), 128); | 327 return color_utils::AlphaBlend(GetColor(TEXT), GetColor(BACKGROUND), 128); |
328 | 328 |
329 case EV_BUBBLE_TEXT_AND_BORDER: | 329 case SECURITY_CHIP_TEXT: |
330 return ui::MaterialDesignController::IsModeMaterial() | 330 return ui::MaterialDesignController::IsModeMaterial() |
331 ? GetSecureTextColor( | 331 ? GetSecureTextColor( |
332 security_state::SecurityStateModel::EV_SECURE) | 332 GetToolbarModel()->GetSecurityLevel(false)) |
333 : SkColorSetRGB(7, 149, 0); | 333 : SkColorSetRGB(7, 149, 0); |
334 } | 334 } |
335 NOTREACHED(); | 335 NOTREACHED(); |
336 return gfx::kPlaceholderColor; | 336 return gfx::kPlaceholderColor; |
337 } | 337 } |
338 | 338 |
339 SkColor LocationBarView::GetSecureTextColor( | 339 SkColor LocationBarView::GetSecureTextColor( |
340 security_state::SecurityStateModel::SecurityLevel security_level) const { | 340 security_state::SecurityStateModel::SecurityLevel security_level) const { |
341 if (security_level == | 341 if (security_level == |
342 security_state::SecurityStateModel::SECURITY_POLICY_WARNING) { | 342 security_state::SecurityStateModel::SECURITY_POLICY_WARNING) { |
343 return GetColor(DEEMPHASIZED_TEXT); | 343 return GetColor(DEEMPHASIZED_TEXT); |
344 } | 344 } |
345 | 345 |
346 SkColor text_color = GetColor(TEXT); | 346 SkColor text_color = GetColor(TEXT); |
347 if ((security_level == security_state::SecurityStateModel::EV_SECURE) || | 347 if ((security_level == security_state::SecurityStateModel::EV_SECURE) || |
348 (security_level == security_state::SecurityStateModel::SECURE) || | 348 (security_level == security_state::SecurityStateModel::SECURE) || |
349 (security_level == security_state::SecurityStateModel::SECURITY_ERROR)) { | 349 (security_level == security_state::SecurityStateModel::SECURITY_ERROR)) { |
350 if (ui::MaterialDesignController::IsModeMaterial()) { | 350 if (ui::MaterialDesignController::IsModeMaterial()) { |
351 if (color_utils::IsDark(GetColor(BACKGROUND))) | 351 if (color_utils::IsDark(GetColor(BACKGROUND))) |
352 return text_color; | 352 return text_color; |
353 if (security_level == security_state::SecurityStateModel::SECURITY_ERROR) | 353 if (security_level == security_state::SecurityStateModel::SECURITY_ERROR) |
354 text_color = gfx::kGoogleRed700; | 354 text_color = gfx::kGoogleRed700; |
355 else | 355 else |
356 text_color = gfx::kGoogleGreen700; | 356 text_color = gfx::kGoogleGreen700; |
357 } else if (security_level == | 357 } else if (security_level == |
358 security_state::SecurityStateModel::SECURITY_ERROR) { | 358 security_state::SecurityStateModel::SECURITY_ERROR) { |
359 text_color = SkColorSetRGB(162, 0, 0); | 359 text_color = SkColorSetRGB(162, 0, 0); |
360 } else { | 360 } else { |
361 text_color = GetColor(EV_BUBBLE_TEXT_AND_BORDER); | 361 text_color = GetColor(SECURITY_CHIP_TEXT); |
362 } | 362 } |
363 } | 363 } |
364 return color_utils::GetReadableColor(text_color, GetColor(BACKGROUND)); | 364 return color_utils::GetReadableColor(text_color, GetColor(BACKGROUND)); |
365 } | 365 } |
366 | 366 |
367 void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) { | 367 void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) { |
368 DCHECK(zoom_view_); | 368 DCHECK(zoom_view_); |
369 if (RefreshZoomView()) { | 369 if (RefreshZoomView()) { |
370 Layout(); | 370 Layout(); |
371 SchedulePaint(); | 371 SchedulePaint(); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
525 | 525 |
526 min_size.set_height(min_size.height() * size_animation_.GetCurrentValue()); | 526 min_size.set_height(min_size.height() * size_animation_.GetCurrentValue()); |
527 | 527 |
528 const int padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); | 528 const int padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); |
529 | 529 |
530 // Compute width of omnibox-leading content. | 530 // Compute width of omnibox-leading content. |
531 const int edge_thickness = GetHorizontalEdgeThickness(); | 531 const int edge_thickness = GetHorizontalEdgeThickness(); |
532 int leading_width = edge_thickness; | 532 int leading_width = edge_thickness; |
533 if (ShouldShowKeywordBubble()) { | 533 if (ShouldShowKeywordBubble()) { |
534 // The selected keyword view can collapse completely. | 534 // The selected keyword view can collapse completely. |
535 } else if (ShouldShowEVBubble()) { | 535 } else if (ShouldShowSecurityChip()) { |
536 leading_width += GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING) + | 536 base::string16 security_text = GetSecurityText(); |
537 location_icon_view_->GetMinimumSizeForLabelText( | 537 leading_width += |
538 GetToolbarModel()->GetEVCertName()) | 538 GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING) + |
539 .width(); | 539 location_icon_view_->GetMinimumSizeForLabelText(security_text).width(); |
540 } else { | 540 } else { |
541 leading_width += padding + location_icon_view_->GetMinimumSize().width(); | 541 leading_width += padding + location_icon_view_->GetMinimumSize().width(); |
542 } | 542 } |
543 | 543 |
544 // Compute width of omnibox-trailing content. | 544 // Compute width of omnibox-trailing content. |
545 int trailing_width = edge_thickness; | 545 int trailing_width = edge_thickness; |
546 trailing_width += IncrementalMinimumWidth(star_view_) + | 546 trailing_width += IncrementalMinimumWidth(star_view_) + |
547 IncrementalMinimumWidth(translate_icon_view_) + | 547 IncrementalMinimumWidth(translate_icon_view_) + |
548 IncrementalMinimumWidth(open_pdf_in_reader_view_) + | 548 IncrementalMinimumWidth(open_pdf_in_reader_view_) + |
549 IncrementalMinimumWidth(save_credit_card_icon_view_) + | 549 IncrementalMinimumWidth(save_credit_card_icon_view_) + |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
605 (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) { | 605 (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) { |
606 gfx::Image image = extensions::OmniboxAPI::Get(profile())-> | 606 gfx::Image image = extensions::OmniboxAPI::Get(profile())-> |
607 GetOmniboxIcon(template_url->GetExtensionId()); | 607 GetOmniboxIcon(template_url->GetExtensionId()); |
608 selected_keyword_view_->SetImage(image.AsImageSkia()); | 608 selected_keyword_view_->SetImage(image.AsImageSkia()); |
609 selected_keyword_view_->set_is_extension_icon(true); | 609 selected_keyword_view_->set_is_extension_icon(true); |
610 } else { | 610 } else { |
611 selected_keyword_view_->ResetImage(); | 611 selected_keyword_view_->ResetImage(); |
612 selected_keyword_view_->set_is_extension_icon(false); | 612 selected_keyword_view_->set_is_extension_icon(false); |
613 } | 613 } |
614 } | 614 } |
615 } else if (ShouldShowEVBubble()) { | 615 } else if (ShouldShowSecurityChip()) { |
616 location_icon_view_->SetLabel(GetToolbarModel()->GetEVCertName()); | 616 location_icon_view_->SetLabel(GetSecurityText()); |
617 location_icon_view_->SetBackground(true); | 617 location_icon_view_->SetBackground(true); |
618 // The largest fraction of the omnibox that can be taken by the EV bubble. | 618 // The largest fraction of the omnibox that can be taken by the EV bubble. |
619 const double kMaxBubbleFraction = 0.5; | 619 const double kMaxBubbleFraction = 0.5; |
620 leading_decorations.AddDecoration( | 620 leading_decorations.AddDecoration( |
621 vertical_padding, location_height, false, kMaxBubbleFraction, | 621 vertical_padding, location_height, false, kMaxBubbleFraction, |
622 bubble_horizontal_padding, item_padding, location_icon_view_); | 622 bubble_horizontal_padding, item_padding, location_icon_view_); |
623 } else { | 623 } else { |
624 leading_decorations.AddDecoration(vertical_padding, location_height, | 624 leading_decorations.AddDecoration(vertical_padding, location_height, |
625 location_icon_view_); | 625 location_icon_view_); |
626 } | 626 } |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
783 } | 783 } |
784 } | 784 } |
785 | 785 |
786 void LocationBarView::Update(const WebContents* contents) { | 786 void LocationBarView::Update(const WebContents* contents) { |
787 RefreshContentSettingViews(); | 787 RefreshContentSettingViews(); |
788 RefreshZoomView(); | 788 RefreshZoomView(); |
789 RefreshPageActionViews(); | 789 RefreshPageActionViews(); |
790 RefreshTranslateIcon(); | 790 RefreshTranslateIcon(); |
791 RefreshSaveCreditCardIconView(); | 791 RefreshSaveCreditCardIconView(); |
792 RefreshManagePasswordsIconView(); | 792 RefreshManagePasswordsIconView(); |
793 content::WebContents* web_contents_for_sub_views = | 793 WebContents* web_contents_for_sub_views = |
794 GetToolbarModel()->input_in_progress() ? nullptr : GetWebContents(); | 794 GetToolbarModel()->input_in_progress() ? nullptr : GetWebContents(); |
795 open_pdf_in_reader_view_->Update(web_contents_for_sub_views); | 795 open_pdf_in_reader_view_->Update(web_contents_for_sub_views); |
796 | 796 |
797 if (star_view_) | 797 if (star_view_) |
798 UpdateBookmarkStarVisibility(); | 798 UpdateBookmarkStarVisibility(); |
799 | 799 |
800 if (contents) | 800 if (contents) |
801 omnibox_view_->OnTabChanged(contents); | 801 omnibox_view_->OnTabChanged(contents); |
802 else | 802 else |
803 omnibox_view_->Update(); | 803 omnibox_view_->Update(); |
804 | 804 |
805 if (!ShouldShowSecurityChip()) { | |
806 location_icon_view_->HideSecurityChip(); | |
807 } else if (contents) { | |
808 location_icon_view_->ShowSecurityChip(); | |
809 } else { | |
810 location_icon_view_->AnimateSecurityChip(); | |
811 } | |
Peter Kasting
2016/08/26 20:59:12
AnimateSecurityChip() is unclear, because it doesn
Kevin Bailey
2016/08/29 13:38:10
That would be trivially fixed by adopting Sarah's
| |
812 | |
805 OnChanged(); // NOTE: Calls Layout(). | 813 OnChanged(); // NOTE: Calls Layout(). |
806 } | 814 } |
807 | 815 |
808 void LocationBarView::ResetTabState(WebContents* contents) { | 816 void LocationBarView::ResetTabState(WebContents* contents) { |
809 omnibox_view_->ResetTabState(contents); | 817 omnibox_view_->ResetTabState(contents); |
810 } | 818 } |
811 | 819 |
812 //////////////////////////////////////////////////////////////////////////////// | 820 //////////////////////////////////////////////////////////////////////////////// |
813 // LocationBarView, public OmniboxEditController implementation: | 821 // LocationBarView, public OmniboxEditController implementation: |
814 | 822 |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1031 if (browser) | 1039 if (browser) |
1032 FirstRunBubble::ShowBubble(browser, location_icon_view_); | 1040 FirstRunBubble::ShowBubble(browser, location_icon_view_); |
1033 #endif | 1041 #endif |
1034 } | 1042 } |
1035 | 1043 |
1036 bool LocationBarView::HasValidSuggestText() const { | 1044 bool LocationBarView::HasValidSuggestText() const { |
1037 return suggested_text_view_->visible() && | 1045 return suggested_text_view_->visible() && |
1038 !suggested_text_view_->size().IsEmpty(); | 1046 !suggested_text_view_->size().IsEmpty(); |
1039 } | 1047 } |
1040 | 1048 |
1049 base::string16 LocationBarView::GetSecurityText() const { | |
1050 return ShouldShowEVBubble() ? GetToolbarModel()->GetEVCertName() | |
1051 : GetToolbarModel()->GetSecureVerboseText(); | |
1052 } | |
1053 | |
1041 bool LocationBarView::ShouldShowKeywordBubble() const { | 1054 bool LocationBarView::ShouldShowKeywordBubble() const { |
1042 return !omnibox_view_->model()->keyword().empty() && | 1055 return !omnibox_view_->model()->keyword().empty() && |
1043 !omnibox_view_->model()->is_keyword_hint(); | 1056 !omnibox_view_->model()->is_keyword_hint(); |
1044 } | 1057 } |
1045 | 1058 |
1046 bool LocationBarView::ShouldShowEVBubble() const { | 1059 bool LocationBarView::ShouldShowEVBubble() const { |
1047 return (GetToolbarModel()->GetSecurityLevel(false) == | 1060 return (GetToolbarModel()->GetSecurityLevel(false) == |
1048 security_state::SecurityStateModel::EV_SECURE); | 1061 security_state::SecurityStateModel::EV_SECURE); |
1049 } | 1062 } |
1050 | 1063 |
1064 bool LocationBarView::ShouldShowSecurityChip() const { | |
1065 using SecurityLevel = security_state::SecurityStateModel::SecurityLevel; | |
1066 SecurityLevel level = GetToolbarModel()->GetSecurityLevel(false); | |
1067 return level == SecurityLevel::SECURE || level == SecurityLevel::EV_SECURE || | |
1068 level == SecurityLevel::SECURITY_ERROR; | |
1069 } | |
1070 | |
1051 //////////////////////////////////////////////////////////////////////////////// | 1071 //////////////////////////////////////////////////////////////////////////////// |
1052 // LocationBarView, private LocationBar implementation: | 1072 // LocationBarView, private LocationBar implementation: |
1053 | 1073 |
1054 void LocationBarView::ShowFirstRunBubble() { | 1074 void LocationBarView::ShowFirstRunBubble() { |
1055 // Wait until search engines have loaded to show the first run bubble. | 1075 // Wait until search engines have loaded to show the first run bubble. |
1056 TemplateURLService* url_service = | 1076 TemplateURLService* url_service = |
1057 TemplateURLServiceFactory::GetForProfile(profile()); | 1077 TemplateURLServiceFactory::GetForProfile(profile()); |
1058 if (!url_service->loaded()) { | 1078 if (!url_service->loaded()) { |
1059 template_url_service_ = url_service; | 1079 template_url_service_ = url_service; |
1060 template_url_service_->AddObserver(this); | 1080 template_url_service_->AddObserver(this); |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1385 // LocationBarView, private TemplateURLServiceObserver implementation: | 1405 // LocationBarView, private TemplateURLServiceObserver implementation: |
1386 | 1406 |
1387 void LocationBarView::OnTemplateURLServiceChanged() { | 1407 void LocationBarView::OnTemplateURLServiceChanged() { |
1388 template_url_service_->RemoveObserver(this); | 1408 template_url_service_->RemoveObserver(this); |
1389 template_url_service_ = nullptr; | 1409 template_url_service_ = nullptr; |
1390 // If the browser is no longer active, let's not show the info bubble, as this | 1410 // 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. | 1411 // would make the browser the active window again. |
1392 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) | 1412 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) |
1393 ShowFirstRunBubble(); | 1413 ShowFirstRunBubble(); |
1394 } | 1414 } |
OLD | NEW |