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

Side by Side Diff: chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm

Issue 2119033002: [Material][Mac] Implement Omnibox Verbose State Chips (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed the verbose for "NOT SECURE" 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" 5 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #import "base/mac/mac_util.h" 9 #import "base/mac/mac_util.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 16 matching lines...) Expand all
27 #include "chrome/browser/translate/translate_service.h" 27 #include "chrome/browser/translate/translate_service.h"
28 #include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h" 28 #include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h"
29 #include "chrome/browser/ui/browser_list.h" 29 #include "chrome/browser/ui/browser_list.h"
30 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 30 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
31 #import "chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.h " 31 #import "chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.h "
32 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" 32 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h"
33 #import "chrome/browser/ui/cocoa/first_run_bubble_controller.h" 33 #import "chrome/browser/ui/cocoa/first_run_bubble_controller.h"
34 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" 34 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h"
35 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" 35 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h"
36 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h" 36 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h"
37 #import "chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.h"
38 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h" 37 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h"
39 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h" 38 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h"
40 #import "chrome/browser/ui/cocoa/location_bar/manage_passwords_decoration.h" 39 #import "chrome/browser/ui/cocoa/location_bar/manage_passwords_decoration.h"
41 #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h" 40 #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h"
42 #import "chrome/browser/ui/cocoa/location_bar/save_credit_card_decoration.h" 41 #import "chrome/browser/ui/cocoa/location_bar/save_credit_card_decoration.h"
42 #import "chrome/browser/ui/cocoa/location_bar/secure_verbose_bubble_decoration.h "
43 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" 43 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h"
44 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" 44 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h"
45 #import "chrome/browser/ui/cocoa/location_bar/translate_decoration.h" 45 #import "chrome/browser/ui/cocoa/location_bar/translate_decoration.h"
46 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h" 46 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h"
47 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" 47 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
48 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" 48 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
49 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" 49 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
50 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" 50 #include "chrome/browser/ui/content_settings/content_setting_image_model.h"
51 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" 51 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
52 #include "chrome/browser/ui/tabs/tab_strip_model.h" 52 #include "chrome/browser/ui/tabs/tab_strip_model.h"
53 #include "chrome/common/chrome_switches.h" 53 #include "chrome/common/chrome_switches.h"
54 #include "chrome/common/pref_names.h" 54 #include "chrome/common/pref_names.h"
55 #include "components/bookmarks/common/bookmark_pref_names.h" 55 #include "components/bookmarks/common/bookmark_pref_names.h"
56 #import "components/omnibox/browser/omnibox_popup_model.h" 56 #import "components/omnibox/browser/omnibox_popup_model.h"
57 #include "components/prefs/pref_service.h" 57 #include "components/prefs/pref_service.h"
58 #include "components/search_engines/template_url.h" 58 #include "components/search_engines/template_url.h"
59 #include "components/search_engines/template_url_service.h" 59 #include "components/search_engines/template_url_service.h"
60 #include "components/security_state/security_state_model.h"
61 #include "components/translate/core/browser/language_state.h" 60 #include "components/translate/core/browser/language_state.h"
62 #include "components/zoom/zoom_controller.h" 61 #include "components/zoom/zoom_controller.h"
63 #include "components/zoom/zoom_event_manager.h" 62 #include "components/zoom/zoom_event_manager.h"
64 #include "content/public/browser/web_contents.h" 63 #include "content/public/browser/web_contents.h"
65 #include "extensions/browser/extension_system.h" 64 #include "extensions/browser/extension_system.h"
66 #include "extensions/common/extension.h" 65 #include "extensions/common/extension.h"
67 #include "grit/components_scaled_resources.h" 66 #include "grit/components_scaled_resources.h"
68 #include "grit/theme_resources.h" 67 #include "grit/theme_resources.h"
69 #include "skia/ext/skia_utils_mac.h" 68 #include "skia/ext/skia_utils_mac.h"
70 #import "ui/base/cocoa/cocoa_base_utils.h" 69 #import "ui/base/cocoa/cocoa_base_utils.h"
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 LocationBarViewMac::LocationBarViewMac(AutocompleteTextField* field, 270 LocationBarViewMac::LocationBarViewMac(AutocompleteTextField* field,
272 CommandUpdater* command_updater, 271 CommandUpdater* command_updater,
273 Profile* profile, 272 Profile* profile,
274 Browser* browser) 273 Browser* browser)
275 : LocationBar(profile), 274 : LocationBar(profile),
276 ChromeOmniboxEditController(command_updater), 275 ChromeOmniboxEditController(command_updater),
277 omnibox_view_(new OmniboxViewMac(this, profile, command_updater, field)), 276 omnibox_view_(new OmniboxViewMac(this, profile, command_updater, field)),
278 field_(field), 277 field_(field),
279 location_icon_decoration_(new LocationIconDecoration(this)), 278 location_icon_decoration_(new LocationIconDecoration(this)),
280 selected_keyword_decoration_(new SelectedKeywordDecoration()), 279 selected_keyword_decoration_(new SelectedKeywordDecoration()),
281 ev_bubble_decoration_( 280 secure_verbose_bubble_decoration_(
282 new EVBubbleDecoration(location_icon_decoration_.get())), 281 new SecureVerboseBubbleDecoration(location_icon_decoration_.get(),
282 this)),
283 save_credit_card_decoration_( 283 save_credit_card_decoration_(
284 new SaveCreditCardDecoration(command_updater)), 284 new SaveCreditCardDecoration(command_updater)),
285 star_decoration_(new StarDecoration(command_updater)), 285 star_decoration_(new StarDecoration(command_updater)),
286 translate_decoration_(new TranslateDecoration(command_updater)), 286 translate_decoration_(new TranslateDecoration(command_updater)),
287 zoom_decoration_(new ZoomDecoration(this)), 287 zoom_decoration_(new ZoomDecoration(this)),
288 keyword_hint_decoration_(new KeywordHintDecoration()), 288 keyword_hint_decoration_(new KeywordHintDecoration()),
289 manage_passwords_decoration_( 289 manage_passwords_decoration_(
290 new ManagePasswordsDecoration(command_updater, this)), 290 new ManagePasswordsDecoration(command_updater, this)),
291 browser_(browser), 291 browser_(browser),
292 location_bar_visible_(true), 292 location_bar_visible_(true),
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 557
558 NSPoint LocationBarViewMac::GetTranslateBubblePoint() const { 558 NSPoint LocationBarViewMac::GetTranslateBubblePoint() const {
559 return [field_ bubblePointForDecoration:translate_decoration_.get()]; 559 return [field_ bubblePointForDecoration:translate_decoration_.get()];
560 } 560 }
561 561
562 NSPoint LocationBarViewMac::GetManagePasswordsBubblePoint() const { 562 NSPoint LocationBarViewMac::GetManagePasswordsBubblePoint() const {
563 return [field_ bubblePointForDecoration:manage_passwords_decoration_.get()]; 563 return [field_ bubblePointForDecoration:manage_passwords_decoration_.get()];
564 } 564 }
565 565
566 NSPoint LocationBarViewMac::GetPageInfoBubblePoint() const { 566 NSPoint LocationBarViewMac::GetPageInfoBubblePoint() const {
567 if (ev_bubble_decoration_->IsVisible()) { 567 if (secure_verbose_bubble_decoration_->IsVisible()) {
568 return [field_ bubblePointForDecoration:ev_bubble_decoration_.get()]; 568 return [field_
569 bubblePointForDecoration:secure_verbose_bubble_decoration_.get()];
569 } else { 570 } else {
570 return [field_ bubblePointForDecoration:location_icon_decoration_.get()]; 571 return [field_ bubblePointForDecoration:location_icon_decoration_.get()];
571 } 572 }
572 } 573 }
573 574
574 void LocationBarViewMac::OnDecorationsChanged() { 575 void LocationBarViewMac::OnDecorationsChanged() {
575 // TODO(shess): The field-editor frame and cursor rects should not 576 // TODO(shess): The field-editor frame and cursor rects should not
576 // change, here. 577 // change, here.
577 [field_ updateMouseTracking]; 578 [field_ updateMouseTracking];
578 [field_ resetFieldEditorFrameIfNeeded]; 579 [field_ resetFieldEditorFrameIfNeeded];
579 [field_ setNeedsDisplay:YES]; 580 [field_ setNeedsDisplay:YES];
580 } 581 }
581 582
582 // TODO(shess): This function should over time grow to closely match 583 // TODO(shess): This function should over time grow to closely match
583 // the views Layout() function. 584 // the views Layout() function.
584 void LocationBarViewMac::Layout() { 585 void LocationBarViewMac::Layout() {
585 AutocompleteTextFieldCell* cell = [field_ cell]; 586 AutocompleteTextFieldCell* cell = [field_ cell];
586 587
587 // Reset the left-hand decorations. 588 // Reset the left-hand decorations.
588 // TODO(shess): Shortly, this code will live somewhere else, like in 589 // TODO(shess): Shortly, this code will live somewhere else, like in
589 // the constructor. I am still wrestling with how best to deal with 590 // the constructor. I am still wrestling with how best to deal with
590 // right-hand decorations, which are not a static set. 591 // right-hand decorations, which are not a static set.
591 [cell clearDecorations]; 592 [cell clearDecorations];
592 [cell addLeftDecoration:location_icon_decoration_.get()]; 593 [cell addLeftDecoration:location_icon_decoration_.get()];
593 [cell addLeftDecoration:selected_keyword_decoration_.get()]; 594 [cell addLeftDecoration:selected_keyword_decoration_.get()];
594 [cell addLeftDecoration:ev_bubble_decoration_.get()]; 595 [cell addLeftDecoration:secure_verbose_bubble_decoration_.get()];
595 [cell addRightDecoration:star_decoration_.get()]; 596 [cell addRightDecoration:star_decoration_.get()];
596 [cell addRightDecoration:translate_decoration_.get()]; 597 [cell addRightDecoration:translate_decoration_.get()];
597 [cell addRightDecoration:zoom_decoration_.get()]; 598 [cell addRightDecoration:zoom_decoration_.get()];
598 [cell addRightDecoration:save_credit_card_decoration_.get()]; 599 [cell addRightDecoration:save_credit_card_decoration_.get()];
599 [cell addRightDecoration:manage_passwords_decoration_.get()]; 600 [cell addRightDecoration:manage_passwords_decoration_.get()];
600 601
601 // Note that display order is right to left. 602 // Note that display order is right to left.
602 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { 603 for (size_t i = 0; i < page_action_decorations_.size(); ++i) {
603 [cell addRightDecoration:page_action_decorations_[i]]; 604 [cell addRightDecoration:page_action_decorations_[i]];
604 } 605 }
605 606
606 for (ScopedVector<ContentSettingDecoration>::iterator i = 607 for (ScopedVector<ContentSettingDecoration>::iterator i =
607 content_setting_decorations_.begin(); 608 content_setting_decorations_.begin();
608 i != content_setting_decorations_.end(); ++i) { 609 i != content_setting_decorations_.end(); ++i) {
609 [cell addRightDecoration:*i]; 610 [cell addRightDecoration:*i];
610 } 611 }
611 612
612 [cell addRightDecoration:keyword_hint_decoration_.get()]; 613 [cell addRightDecoration:keyword_hint_decoration_.get()];
613 614
614 // By default only the location icon is visible. 615 // By default only the location icon is visible.
615 location_icon_decoration_->SetVisible(true); 616 location_icon_decoration_->SetVisible(true);
616 selected_keyword_decoration_->SetVisible(false); 617 selected_keyword_decoration_->SetVisible(false);
617 ev_bubble_decoration_->SetVisible(false); 618 secure_verbose_bubble_decoration_->SetVisible(false);
618 keyword_hint_decoration_->SetVisible(false); 619 keyword_hint_decoration_->SetVisible(false);
619 620
620 // Get the keyword to use for keyword-search and hinting. 621 // Get the keyword to use for keyword-search and hinting.
621 const base::string16 keyword = omnibox_view_->model()->keyword(); 622 const base::string16 keyword = omnibox_view_->model()->keyword();
622 base::string16 short_name; 623 base::string16 short_name;
623 bool is_extension_keyword = false; 624 bool is_extension_keyword = false;
624 if (!keyword.empty()) { 625 if (!keyword.empty()) {
625 short_name = TemplateURLServiceFactory::GetForProfile(profile())-> 626 short_name = TemplateURLServiceFactory::GetForProfile(profile())->
626 GetKeywordShortName(keyword, &is_extension_keyword); 627 GetKeywordShortName(keyword, &is_extension_keyword);
627 } 628 }
628 629
629 const bool is_keyword_hint = omnibox_view_->model()->is_keyword_hint(); 630 const bool is_keyword_hint = omnibox_view_->model()->is_keyword_hint();
630 if (!keyword.empty() && !is_keyword_hint) { 631 if (!keyword.empty() && !is_keyword_hint) {
631 // Switch from location icon to keyword mode. 632 // Switch from location icon to keyword mode.
632 location_icon_decoration_->SetVisible(false); 633 location_icon_decoration_->SetVisible(false);
633 selected_keyword_decoration_->SetVisible(true); 634 selected_keyword_decoration_->SetVisible(true);
634 selected_keyword_decoration_->SetKeyword(short_name, is_extension_keyword); 635 selected_keyword_decoration_->SetKeyword(short_name, is_extension_keyword);
635 // Note: the first time through this code path the 636 // Note: the first time through this code path the
636 // |selected_keyword_decoration_| has no image set because under Material 637 // |selected_keyword_decoration_| has no image set because under Material
637 // Design we need to set its color, which we cannot do until we know the 638 // Design we need to set its color, which we cannot do until we know the
638 // theme (by being installed in a browser window). 639 // theme (by being installed in a browser window).
639 selected_keyword_decoration_->SetImage(GetKeywordImage(keyword)); 640 selected_keyword_decoration_->SetImage(GetKeywordImage(keyword));
640 } else if (ShouldShowEVBubble()) { 641 } else if (!keyword.empty() && is_keyword_hint) {
641 // Switch from location icon to show the EV bubble instead. 642 keyword_hint_decoration_->SetKeyword(short_name, is_extension_keyword);
643 keyword_hint_decoration_->SetVisible(true);
644 } else if (ShouldShowSecureVerbose()) {
645 // Switch from location icon to show the SecureVerbose bubble instead.
642 location_icon_decoration_->SetVisible(false); 646 location_icon_decoration_->SetVisible(false);
643 ev_bubble_decoration_->SetVisible(true); 647 secure_verbose_bubble_decoration_->SetVisible(true);
644 648
645 base::string16 label(GetToolbarModel()->GetEVCertName()); 649 base::string16 label = ShouldShowEVBubble()
646 ev_bubble_decoration_->SetFullLabel(base::SysUTF16ToNSString(label)); 650 ? GetToolbarModel()->GetEVCertName()
647 } else if (!keyword.empty() && is_keyword_hint) { 651 : GetToolbarModel()->GetSecureVerboseText();
648 keyword_hint_decoration_->SetKeyword(short_name, 652 secure_verbose_bubble_decoration_->SetFullLabel(
649 is_extension_keyword); 653 base::SysUTF16ToNSString(label));
650 keyword_hint_decoration_->SetVisible(true);
651 } 654 }
652 655
653 // These need to change anytime the layout changes. 656 // These need to change anytime the layout changes.
654 // TODO(shess): Anytime the field editor might have changed, the 657 // TODO(shess): Anytime the field editor might have changed, the
655 // cursor rects almost certainly should have changed. The tooltips 658 // cursor rects almost certainly should have changed. The tooltips
656 // might change even when the rects don't change. 659 // might change even when the rects don't change.
657 OnDecorationsChanged(); 660 OnDecorationsChanged();
658 } 661 }
659 662
660 void LocationBarViewMac::RedrawDecoration(LocationBarDecoration* decoration) { 663 void LocationBarViewMac::RedrawDecoration(LocationBarDecoration* decoration) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 else 732 else
730 omnibox_view_->Update(); 733 omnibox_view_->Update();
731 OnChanged(); 734 OnChanged();
732 } 735 }
733 736
734 void LocationBarViewMac::UpdateWithoutTabRestore() { 737 void LocationBarViewMac::UpdateWithoutTabRestore() {
735 Update(nullptr); 738 Update(nullptr);
736 } 739 }
737 740
738 void LocationBarViewMac::UpdateLocationIcon() { 741 void LocationBarViewMac::UpdateLocationIcon() {
739 bool in_dark_mode = IsLocationBarDark(); 742 SkColor vector_icon_color = GetLocationBarIconColor();
740 743 gfx::VectorIconId vector_icon_id =
741 SkColor vector_icon_color = gfx::kPlaceholderColor; 744 ShouldShowEVBubble() ? gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID
742 gfx::VectorIconId vector_icon_id = gfx::VectorIconId::VECTOR_ICON_NONE; 745 : omnibox_view_->GetVectorIcon();
743 if (ShouldShowEVBubble()) {
744 vector_icon_id = gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID;
745 vector_icon_color = gfx::kGoogleGreen700;
746 } else {
747 vector_icon_id = omnibox_view_->GetVectorIcon();
748 security_state::SecurityStateModel::SecurityLevel security_level =
749 GetToolbarModel()->GetSecurityLevel(false);
750 if (security_level == security_state::SecurityStateModel::NONE) {
751 vector_icon_color = gfx::kChromeIconGrey;
752 } else {
753 NSColor* sRGBColor =
754 OmniboxViewMac::GetSecureTextColor(security_level, in_dark_mode);
755 NSColor* deviceColor =
756 [sRGBColor colorUsingColorSpace:[NSColorSpace deviceRGBColorSpace]];
757 vector_icon_color = skia::NSDeviceColorToSkColor(deviceColor);
758 }
759 }
760
761 // If the theme is dark, then the color should always be
762 // kMaterialDarkVectorIconColor.
763 if (in_dark_mode)
764 vector_icon_color = kMaterialDarkVectorIconColor;
765 746
766 DCHECK(vector_icon_id != gfx::VectorIconId::VECTOR_ICON_NONE); 747 DCHECK(vector_icon_id != gfx::VectorIconId::VECTOR_ICON_NONE);
767 NSImage* image = 748 NSImage* image =
768 [LocationBarImageRep imageForId:vector_icon_id color:vector_icon_color]; 749 [LocationBarImageRep imageForId:vector_icon_id color:vector_icon_color];
750 location_icon_decoration_->SetImage(image);
751 secure_verbose_bubble_decoration_->SetImage(image);
752 secure_verbose_bubble_decoration_->SetLabelColor(
753 skia::SkColorToSRGBNSColor(vector_icon_color));
769 754
770 location_icon_decoration_->SetImage(image);
771 ev_bubble_decoration_->SetImage(image);
772 Layout(); 755 Layout();
756
757 // If we are showing a new secure verbose, we will have to animate the
758 // decoration. In order to determine if the secure verbose is new, we need
759 // to check if the EV cert is different (if we're showing the EV bubble) or
760 // if the security level has changed.
761 security_state::SecurityStateModel::SecurityLevel current_security =
762 GetToolbarModel()->GetSecurityLevel(false);
763
764 if (ShouldShowSecureVerbose()) {
765 bool should_start_animation = false;
766 if (ShouldShowEVBubble()) {
767 scoped_refptr<net::X509Certificate> updated_cert =
768 GetToolbarModel()->GetCertificate();
769 if (!certificate_.get() || !certificate_->Equals(updated_cert.get())) {
770 certificate_ = updated_cert;
771 should_start_animation = true;
772 }
773 } else {
774 certificate_ = scoped_refptr<net::X509Certificate>();
775 if (security_level_ != current_security)
776 should_start_animation = true;
777 }
778 if (should_start_animation)
779 secure_verbose_bubble_decoration_->StartAnimation();
780 }
781
782 security_level_ = current_security;
773 } 783 }
774 784
775 void LocationBarViewMac::UpdateColorsToMatchTheme() { 785 void LocationBarViewMac::UpdateColorsToMatchTheme() {
776 if (!ui::MaterialDesignController::IsModeMaterial() || 786 if (!ui::MaterialDesignController::IsModeMaterial() ||
777 ![[field_ window] inIncognitoMode]) { 787 ![[field_ window] inIncognitoMode]) {
778 return; 788 return;
779 } 789 }
780 790
781 // Update the location-bar icon. 791 // Update the location-bar icon.
782 UpdateLocationIcon(); 792 UpdateLocationIcon();
(...skipping 14 matching lines...) Expand all
797 807
798 void LocationBarViewMac::OnThemeChanged() { 808 void LocationBarViewMac::OnThemeChanged() {
799 UpdateColorsToMatchTheme(); 809 UpdateColorsToMatchTheme();
800 } 810 }
801 811
802 void LocationBarViewMac::OnChanged() { 812 void LocationBarViewMac::OnChanged() {
803 if (!ui::MaterialDesignController::IsModeMaterial()) { 813 if (!ui::MaterialDesignController::IsModeMaterial()) {
804 const int resource_id = omnibox_view_->GetIcon(); 814 const int resource_id = omnibox_view_->GetIcon();
805 NSImage* image = OmniboxViewMac::ImageForResource(resource_id); 815 NSImage* image = OmniboxViewMac::ImageForResource(resource_id);
806 location_icon_decoration_->SetImage(image); 816 location_icon_decoration_->SetImage(image);
807 ev_bubble_decoration_->SetImage(image); 817 secure_verbose_bubble_decoration_->SetImage(image);
808 Layout(); 818 Layout();
809 return; 819 return;
810 } 820 }
811 UpdateLocationIcon(); 821 UpdateLocationIcon();
812 } 822 }
813 823
814 void LocationBarViewMac::ShowURL() { 824 void LocationBarViewMac::ShowURL() {
815 omnibox_view_->ShowURL(); 825 omnibox_view_->ShowURL();
816 } 826 }
817 827
818 ToolbarModel* LocationBarViewMac::GetToolbarModel() { 828 ToolbarModel* LocationBarViewMac::GetToolbarModel() {
819 return browser_->toolbar_model(); 829 return browser_->toolbar_model();
820 } 830 }
821 831
822 const ToolbarModel* LocationBarViewMac::GetToolbarModel() const { 832 const ToolbarModel* LocationBarViewMac::GetToolbarModel() const {
823 return browser_->toolbar_model(); 833 return browser_->toolbar_model();
824 } 834 }
825 835
826 WebContents* LocationBarViewMac::GetWebContents() { 836 WebContents* LocationBarViewMac::GetWebContents() {
827 return browser_->tab_strip_model()->GetActiveWebContents(); 837 return browser_->tab_strip_model()->GetActiveWebContents();
828 } 838 }
829 839
830 bool LocationBarViewMac::ShouldShowEVBubble() const { 840 bool LocationBarViewMac::ShouldShowEVBubble() const {
831 return (GetToolbarModel()->GetSecurityLevel(false) == 841 return (GetToolbarModel()->GetSecurityLevel(false) ==
832 security_state::SecurityStateModel::EV_SECURE); 842 security_state::SecurityStateModel::EV_SECURE);
833 } 843 }
834 844
845 bool LocationBarViewMac::ShouldShowSecureVerbose() const {
846 return ui::MaterialDesignController::IsModeMaterial() &&
847 !omnibox_view_->IsEditingOrEmpty() &&
848 !omnibox_view_->model()->is_keyword_hint() &&
849 GetToolbarModel()->GetSecurityLevel(false) !=
850 security_state::SecurityStateModel::NONE;
851 }
852
835 bool LocationBarViewMac::IsLocationBarDark() const { 853 bool LocationBarViewMac::IsLocationBarDark() const {
836 return [[field_ window] inIncognitoModeWithSystemTheme]; 854 return [[field_ window] inIncognitoModeWithSystemTheme];
837 } 855 }
838 856
839 NSImage* LocationBarViewMac::GetKeywordImage(const base::string16& keyword) { 857 NSImage* LocationBarViewMac::GetKeywordImage(const base::string16& keyword) {
840 const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile( 858 const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile(
841 profile())->GetTemplateURLForKeyword(keyword); 859 profile())->GetTemplateURLForKeyword(keyword);
842 if (template_url && 860 if (template_url &&
843 (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) { 861 (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) {
844 return extensions::OmniboxAPI::Get(profile())-> 862 return extensions::OmniboxAPI::Get(profile())->
845 GetOmniboxIcon(template_url->GetExtensionId()).AsNSImage(); 863 GetOmniboxIcon(template_url->GetExtensionId()).AsNSImage();
846 } 864 }
847 865
848 if (ui::MaterialDesignController::IsModeMaterial()) { 866 if (ui::MaterialDesignController::IsModeMaterial()) {
849 SkColor icon_color = IsLocationBarDark() ? kMaterialDarkVectorIconColor 867 SkColor icon_color = IsLocationBarDark() ? kMaterialDarkVectorIconColor
850 : gfx::kGoogleBlue700; 868 : gfx::kGoogleBlue700;
851 return NSImageFromImageSkiaWithColorSpace( 869 return NSImageFromImageSkiaWithColorSpace(
852 gfx::CreateVectorIcon(gfx::VectorIconId::OMNIBOX_SEARCH, 870 gfx::CreateVectorIcon(gfx::VectorIconId::OMNIBOX_SEARCH,
853 kDefaultIconSize, icon_color), 871 kDefaultIconSize, icon_color),
854 base::mac::GetSRGBColorSpace()); 872 base::mac::GetSRGBColorSpace());
855 } 873 }
856 874
857 return OmniboxViewMac::ImageForResource(IDR_OMNIBOX_SEARCH); 875 return OmniboxViewMac::ImageForResource(IDR_OMNIBOX_SEARCH);
858 } 876 }
859 877
878 SkColor LocationBarViewMac::GetLocationBarIconColor() const {
879 bool in_dark_mode = IsLocationBarDark();
880 if (in_dark_mode)
881 return kMaterialDarkVectorIconColor;
882
883 if (ShouldShowEVBubble())
884 return gfx::kGoogleGreen700;
885
886 security_state::SecurityStateModel::SecurityLevel security_level =
887 GetToolbarModel()->GetSecurityLevel(false);
888
889 if (security_level == security_state::SecurityStateModel::NONE)
890 return gfx::kChromeIconGrey;
891
892 NSColor* sRGBColor =
893 OmniboxViewMac::GetSecureTextColor(security_level, in_dark_mode);
894 NSColor* deviceColor =
895 [sRGBColor colorUsingColorSpace:[NSColorSpace deviceRGBColorSpace]];
896 return skia::NSDeviceColorToSkColor(deviceColor);
897 }
898
860 void LocationBarViewMac::PostNotification(NSString* notification) { 899 void LocationBarViewMac::PostNotification(NSString* notification) {
861 [[NSNotificationCenter defaultCenter] postNotificationName:notification 900 [[NSNotificationCenter defaultCenter] postNotificationName:notification
862 object:[NSValue valueWithPointer:this]]; 901 object:[NSValue valueWithPointer:this]];
863 } 902 }
864 903
865 PageActionDecoration* LocationBarViewMac::GetPageActionDecoration( 904 PageActionDecoration* LocationBarViewMac::GetPageActionDecoration(
866 ExtensionAction* page_action) { 905 ExtensionAction* page_action) {
867 DCHECK(page_action); 906 DCHECK(page_action);
868 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { 907 for (size_t i = 0; i < page_action_decorations_.size(); ++i) {
869 if (page_action_decorations_[i]->GetPageAction() == page_action) 908 if (page_action_decorations_[i]->GetPageAction() == page_action)
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 icons_updated |= 982 icons_updated |=
944 content_setting_decorations_[i]->UpdateFromWebContents(web_contents); 983 content_setting_decorations_[i]->UpdateFromWebContents(web_contents);
945 } 984 }
946 return icons_updated; 985 return icons_updated;
947 } 986 }
948 987
949 void LocationBarViewMac::ShowFirstRunBubbleInternal() { 988 void LocationBarViewMac::ShowFirstRunBubbleInternal() {
950 if (!field_ || ![field_ window]) 989 if (!field_ || ![field_ window])
951 return; 990 return;
952 991
953 // The first run bubble's left edge should line up with the left edge of the 992 // The first run bubble's left edge should line up with the left eƒdge of the
upolat 2016/07/08 22:17:59 typo: edge?
spqchan 2016/07/11 17:57:08 Done.
954 // omnibox. This is different from other bubbles, which line up at a point 993 // omnibox. This is different from other bubbles, which line up at a point
955 // set by their top arrow. Because the BaseBubbleController adjusts the 994 // set by their top arrow. Because the BaseBubbleController adjusts the
956 // window origin left to account for the arrow spacing, the first run bubble 995 // window origin left to account for the arrow spacing, the first run bubble
957 // moves the window origin right by this spacing, so that the 996 // moves the window origin right by this spacing, so that the
958 // BaseBubbleController will move it back to the correct position. 997 // BaseBubbleController will move it back to the correct position.
959 const NSPoint kOffset = NSMakePoint( 998 const NSPoint kOffset = NSMakePoint(
960 info_bubble::kBubbleArrowXOffset + info_bubble::kBubbleArrowWidth/2.0, 999 info_bubble::kBubbleArrowXOffset + info_bubble::kBubbleArrowWidth/2.0,
961 kFirstRunBubbleYOffset); 1000 kFirstRunBubbleYOffset);
962 [FirstRunBubbleController showForView:field_ 1001 [FirstRunBubbleController showForView:field_
963 offset:kOffset 1002 offset:kOffset
(...skipping 24 matching lines...) Expand all
988 1027
989 return zoom_decoration_->UpdateIfNecessary( 1028 return zoom_decoration_->UpdateIfNecessary(
990 zoom::ZoomController::FromWebContents(web_contents), default_zoom_changed, 1029 zoom::ZoomController::FromWebContents(web_contents), default_zoom_changed,
991 IsLocationBarDark()); 1030 IsLocationBarDark());
992 } 1031 }
993 1032
994 void LocationBarViewMac::OnDefaultZoomLevelChanged() { 1033 void LocationBarViewMac::OnDefaultZoomLevelChanged() {
995 if (UpdateZoomDecoration(/*default_zoom_changed=*/true)) 1034 if (UpdateZoomDecoration(/*default_zoom_changed=*/true))
996 OnDecorationsChanged(); 1035 OnDecorationsChanged();
997 } 1036 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698