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

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

Issue 1718563002: Convert location bar decorations to Material Design (Mac). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@md_toolbar
Patch Set: Ready for review. Created 4 years, 9 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 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 #include "components/ui/zoom/zoom_controller.h" 60 #include "components/ui/zoom/zoom_controller.h"
61 #include "components/ui/zoom/zoom_event_manager.h" 61 #include "components/ui/zoom/zoom_event_manager.h"
62 #include "content/public/browser/web_contents.h" 62 #include "content/public/browser/web_contents.h"
63 #include "extensions/browser/extension_system.h" 63 #include "extensions/browser/extension_system.h"
64 #include "extensions/common/extension.h" 64 #include "extensions/common/extension.h"
65 #include "grit/components_scaled_resources.h" 65 #include "grit/components_scaled_resources.h"
66 #include "grit/theme_resources.h" 66 #include "grit/theme_resources.h"
67 #include "skia/ext/skia_utils_mac.h" 67 #include "skia/ext/skia_utils_mac.h"
68 #import "ui/base/cocoa/cocoa_base_utils.h" 68 #import "ui/base/cocoa/cocoa_base_utils.h"
69 #include "ui/base/l10n/l10n_util_mac.h" 69 #include "ui/base/l10n/l10n_util_mac.h"
70 #include "ui/base/material_design/material_design_controller.h"
71 #include "ui/gfx/color_palette.h"
72 #include "ui/gfx/color_utils.h"
70 #include "ui/gfx/image/image.h" 73 #include "ui/gfx/image/image.h"
74 #include "ui/gfx/image/image_skia_util_mac.h"
75 #include "ui/gfx/paint_vector_icon.h"
76 #include "ui/gfx/vector_icons_public.h"
71 77
72 using content::WebContents; 78 using content::WebContents;
73 79
74 namespace { 80 namespace {
75 81
76 // Vertical space between the bottom edge of the location_bar and the first run 82 // Vertical space between the bottom edge of the location_bar and the first run
77 // bubble arrow point. 83 // bubble arrow point.
78 const static int kFirstRunBubbleYOffset = 1; 84 const static int kFirstRunBubbleYOffset = 1;
79 85
80 } // namespace 86 } // namespace
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 WebContents* web_contents = GetWebContents(); 196 WebContents* web_contents = GetWebContents();
191 if (!web_contents) 197 if (!web_contents)
192 return; 198 return;
193 199
194 // |controller| may be nullptr due to lazy initialization. 200 // |controller| may be nullptr due to lazy initialization.
195 autofill::SaveCardBubbleControllerImpl* controller = 201 autofill::SaveCardBubbleControllerImpl* controller =
196 autofill::SaveCardBubbleControllerImpl::FromWebContents(web_contents); 202 autofill::SaveCardBubbleControllerImpl::FromWebContents(web_contents);
197 bool enabled = controller && controller->IsIconVisible(); 203 bool enabled = controller && controller->IsIconVisible();
198 command_updater()->UpdateCommandEnabled(IDC_SAVE_CREDIT_CARD_FOR_PAGE, 204 command_updater()->UpdateCommandEnabled(IDC_SAVE_CREDIT_CARD_FOR_PAGE,
199 enabled); 205 enabled);
206 bool inDarkMode = [[field_ window] inIncognitoModeWithSystemTheme];
207 save_credit_card_decoration_->SetIcon(inDarkMode);
200 save_credit_card_decoration_->SetVisible(enabled); 208 save_credit_card_decoration_->SetVisible(enabled);
201 OnDecorationsChanged(); 209 OnDecorationsChanged();
202 } 210 }
203 211
204 void LocationBarViewMac::UpdatePageActions() { 212 void LocationBarViewMac::UpdatePageActions() {
205 RefreshPageActionDecorations(); 213 RefreshPageActionDecorations();
206 Layout(); 214 Layout();
207 215
208 [field_ updateMouseTracking]; 216 [field_ updateMouseTracking];
209 [field_ setNeedsDisplay:YES]; 217 [field_ setNeedsDisplay:YES];
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 if (star_decoration_->starred() == starred) 340 if (star_decoration_->starred() == starred)
333 return; 341 return;
334 342
335 star_decoration_->SetStarred(starred, 343 star_decoration_->SetStarred(starred,
336 [[field_ window] inIncognitoModeWithSystemTheme]); 344 [[field_ window] inIncognitoModeWithSystemTheme]);
337 UpdateBookmarkStarVisibility(); 345 UpdateBookmarkStarVisibility();
338 OnDecorationsChanged(); 346 OnDecorationsChanged();
339 } 347 }
340 348
341 void LocationBarViewMac::SetTranslateIconLit(bool on) { 349 void LocationBarViewMac::SetTranslateIconLit(bool on) {
342 translate_decoration_->SetLit(on); 350 bool inDarkMode = [[field_ window] inIncognitoModeWithSystemTheme];
351 translate_decoration_->SetLit(on, inDarkMode);
343 OnDecorationsChanged(); 352 OnDecorationsChanged();
344 } 353 }
345 354
346 void LocationBarViewMac::ZoomChangedForActiveTab(bool can_show_bubble) { 355 void LocationBarViewMac::ZoomChangedForActiveTab(bool can_show_bubble) {
347 bool changed = UpdateZoomDecoration(/*default_zoom_changed=*/false); 356 bool changed = UpdateZoomDecoration(/*default_zoom_changed=*/false);
348 if (changed) 357 if (changed)
349 OnDecorationsChanged(); 358 OnDecorationsChanged();
350 359
351 if (can_show_bubble && zoom_decoration_->IsVisible()) 360 if (can_show_bubble && zoom_decoration_->IsVisible())
352 zoom_decoration_->ShowBubble(YES); 361 zoom_decoration_->ShowBubble(YES);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 GetKeywordShortName(keyword, &is_extension_keyword); 449 GetKeywordShortName(keyword, &is_extension_keyword);
441 } 450 }
442 451
443 const bool is_keyword_hint = omnibox_view_->model()->is_keyword_hint(); 452 const bool is_keyword_hint = omnibox_view_->model()->is_keyword_hint();
444 if (!keyword.empty() && !is_keyword_hint) { 453 if (!keyword.empty() && !is_keyword_hint) {
445 // Switch from location icon to keyword mode. 454 // Switch from location icon to keyword mode.
446 location_icon_decoration_->SetVisible(false); 455 location_icon_decoration_->SetVisible(false);
447 selected_keyword_decoration_->SetVisible(true); 456 selected_keyword_decoration_->SetVisible(true);
448 selected_keyword_decoration_->SetKeyword(short_name, is_extension_keyword); 457 selected_keyword_decoration_->SetKeyword(short_name, is_extension_keyword);
449 selected_keyword_decoration_->SetImage(GetKeywordImage(keyword)); 458 selected_keyword_decoration_->SetImage(GetKeywordImage(keyword));
450 } else if (GetToolbarModel()->GetSecurityLevel(false) == 459 } else if (ShouldShowEVBubble()) {
451 security_state::SecurityStateModel::EV_SECURE) {
452 // Switch from location icon to show the EV bubble instead. 460 // Switch from location icon to show the EV bubble instead.
453 location_icon_decoration_->SetVisible(false); 461 location_icon_decoration_->SetVisible(false);
454 ev_bubble_decoration_->SetVisible(true); 462 ev_bubble_decoration_->SetVisible(true);
455 463
456 base::string16 label(GetToolbarModel()->GetEVCertName()); 464 base::string16 label(GetToolbarModel()->GetEVCertName());
457 ev_bubble_decoration_->SetFullLabel(base::SysUTF16ToNSString(label)); 465 ev_bubble_decoration_->SetFullLabel(base::SysUTF16ToNSString(label));
458 } else if (!keyword.empty() && is_keyword_hint) { 466 } else if (!keyword.empty() && is_keyword_hint) {
459 keyword_hint_decoration_->SetKeyword(short_name, 467 keyword_hint_decoration_->SetKeyword(short_name,
460 is_extension_keyword); 468 is_extension_keyword);
461 keyword_hint_decoration_->SetVisible(true); 469 keyword_hint_decoration_->SetVisible(true);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 omnibox_view_->OnTabChanged(contents); 547 omnibox_view_->OnTabChanged(contents);
540 else 548 else
541 omnibox_view_->Update(); 549 omnibox_view_->Update();
542 OnChanged(); 550 OnChanged();
543 } 551 }
544 552
545 void LocationBarViewMac::UpdateWithoutTabRestore() { 553 void LocationBarViewMac::UpdateWithoutTabRestore() {
546 Update(nullptr); 554 Update(nullptr);
547 } 555 }
548 556
549 void LocationBarViewMac::OnChanged() { 557 void LocationBarViewMac::UpdateLocationIcon() {
550 // Update the location-bar icon. 558 bool inDarkMode = [[field_ window] inIncognitoModeWithSystemTheme];
551 const int resource_id = omnibox_view_->GetIcon(); 559
552 NSImage* image = OmniboxViewMac::ImageForResource(resource_id); 560 SkColor vectorIconColor = gfx::kPlaceholderColor;
561 gfx::VectorIconId vectorIconId = gfx::VectorIconId::VECTOR_ICON_NONE;
562 const int kIconSize = 16;
563 if (ShouldShowEVBubble()) {
564 vectorIconId = gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID_IN_CHIP;
565 vectorIconColor = gfx::kGoogleGreen700;
566 } else {
567 vectorIconId = omnibox_view_->GetVectorIcon(inDarkMode);
568 if (inDarkMode) {
569 vectorIconColor = SK_ColorWHITE;
570 } else {
571 NSColor* textColor = OmniboxViewMac::BaseTextColor(inDarkMode);
572 vectorIconColor = skia::NSDeviceColorToSkColor(textColor);
573 }
574 }
575
576 DCHECK(vectorIconId != gfx::VectorIconId::VECTOR_ICON_NONE);
577 NSImage* image = NSImageFromImageSkia(gfx::CreateVectorIcon(
578 vectorIconId, kIconSize, vectorIconColor));
579
553 location_icon_decoration_->SetImage(image); 580 location_icon_decoration_->SetImage(image);
554 ev_bubble_decoration_->SetImage(image); 581 ev_bubble_decoration_->SetImage(image);
582
555 Layout(); 583 Layout();
584 }
556 585
557 // Make sure we're displaying the correct icon color for a dark location bar. 586 void LocationBarViewMac::OnAddedToWindow() {
587 if (!ui::MaterialDesignController::IsModeMaterial()) {
588 return;
589 }
590
591 // Update the location-bar icon.
592 UpdateLocationIcon();
593
594 // Make sure we're displaying the correct star color for a dark location bar.
558 if ([[field_ window] inIncognitoModeWithSystemTheme]) { 595 if ([[field_ window] inIncognitoModeWithSystemTheme]) {
559 star_decoration_->SetStarred(star_decoration_->starred(), true); 596 star_decoration_->SetStarred(star_decoration_->starred(), true);
560 } 597 }
561 } 598 }
562 599
600 void LocationBarViewMac::OnChanged() {
601 NSImage* image = nil;
602 if (ui::MaterialDesignController::IsModeMaterial()) {
603 UpdateLocationIcon();
604 } else {
605 const int resource_id = omnibox_view_->GetIcon();
606 image = OmniboxViewMac::ImageForResource(resource_id);
607 location_icon_decoration_->SetImage(image);
608 ev_bubble_decoration_->SetImage(image);
609 Layout();
610 }
611 }
612
563 void LocationBarViewMac::OnSetFocus() { 613 void LocationBarViewMac::OnSetFocus() {
564 // Update the keyword and search hint states. 614 // Update the keyword and search hint states.
565 OnChanged(); 615 OnChanged();
566 } 616 }
567 617
568 void LocationBarViewMac::ShowURL() { 618 void LocationBarViewMac::ShowURL() {
569 omnibox_view_->ShowURL(); 619 omnibox_view_->ShowURL();
570 } 620 }
571 621
572 ToolbarModel* LocationBarViewMac::GetToolbarModel() { 622 ToolbarModel* LocationBarViewMac::GetToolbarModel() {
573 return browser_->toolbar_model(); 623 return browser_->toolbar_model();
574 } 624 }
575 625
576 const ToolbarModel* LocationBarViewMac::GetToolbarModel() const { 626 const ToolbarModel* LocationBarViewMac::GetToolbarModel() const {
577 return browser_->toolbar_model(); 627 return browser_->toolbar_model();
578 } 628 }
579 629
580 WebContents* LocationBarViewMac::GetWebContents() { 630 WebContents* LocationBarViewMac::GetWebContents() {
581 return browser_->tab_strip_model()->GetActiveWebContents(); 631 return browser_->tab_strip_model()->GetActiveWebContents();
582 } 632 }
583 633
634 bool LocationBarViewMac::ShouldShowEVBubble() const {
635 return (GetToolbarModel()->GetSecurityLevel(false) ==
636 security_state::SecurityStateModel::EV_SECURE);
637 }
638
584 NSImage* LocationBarViewMac::GetKeywordImage(const base::string16& keyword) { 639 NSImage* LocationBarViewMac::GetKeywordImage(const base::string16& keyword) {
585 const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile( 640 const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile(
586 profile())->GetTemplateURLForKeyword(keyword); 641 profile())->GetTemplateURLForKeyword(keyword);
587 if (template_url && 642 if (template_url &&
588 (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) { 643 (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) {
589 return extensions::OmniboxAPI::Get(profile())-> 644 return extensions::OmniboxAPI::Get(profile())->
590 GetOmniboxIcon(template_url->GetExtensionId()).AsNSImage(); 645 GetOmniboxIcon(template_url->GetExtensionId()).AsNSImage();
591 } 646 }
592 647
593 return OmniboxViewMac::ImageForResource(IDR_OMNIBOX_SEARCH); 648 return ui::MaterialDesignController::IsModeMaterial()
649 ? NSImageFromImageSkia(gfx::CreateVectorIcon(
650 gfx::VectorIconId::OMNIBOX_SEARCH, 16, gfx::kGoogleBlue700))
651 : OmniboxViewMac::ImageForResource(IDR_OMNIBOX_SEARCH);
594 } 652 }
595 653
596 void LocationBarViewMac::PostNotification(NSString* notification) { 654 void LocationBarViewMac::PostNotification(NSString* notification) {
597 [[NSNotificationCenter defaultCenter] postNotificationName:notification 655 [[NSNotificationCenter defaultCenter] postNotificationName:notification
598 object:[NSValue valueWithPointer:this]]; 656 object:[NSValue valueWithPointer:this]];
599 } 657 }
600 658
601 PageActionDecoration* LocationBarViewMac::GetPageActionDecoration( 659 PageActionDecoration* LocationBarViewMac::GetPageActionDecoration(
602 ExtensionAction* page_action) { 660 ExtensionAction* page_action) {
603 DCHECK(page_action); 661 DCHECK(page_action);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 return; 764 return;
707 765
708 WebContents* web_contents = GetWebContents(); 766 WebContents* web_contents = GetWebContents();
709 if (!web_contents) 767 if (!web_contents)
710 return; 768 return;
711 translate::LanguageState& language_state = 769 translate::LanguageState& language_state =
712 ChromeTranslateClient::FromWebContents(web_contents)->GetLanguageState(); 770 ChromeTranslateClient::FromWebContents(web_contents)->GetLanguageState();
713 bool enabled = language_state.translate_enabled(); 771 bool enabled = language_state.translate_enabled();
714 command_updater()->UpdateCommandEnabled(IDC_TRANSLATE_PAGE, enabled); 772 command_updater()->UpdateCommandEnabled(IDC_TRANSLATE_PAGE, enabled);
715 translate_decoration_->SetVisible(enabled); 773 translate_decoration_->SetVisible(enabled);
716 translate_decoration_->SetLit(language_state.IsPageTranslated()); 774 bool inDarkMode = [[field_ window] inIncognitoModeWithSystemTheme];
775 translate_decoration_->SetLit(language_state.IsPageTranslated(), inDarkMode);
717 } 776 }
718 777
719 bool LocationBarViewMac::UpdateZoomDecoration(bool default_zoom_changed) { 778 bool LocationBarViewMac::UpdateZoomDecoration(bool default_zoom_changed) {
720 WebContents* web_contents = GetWebContents(); 779 WebContents* web_contents = GetWebContents();
721 if (!web_contents) 780 if (!web_contents)
722 return false; 781 return false;
723 782
783 bool inDarkMode = [[field_ window] inIncognitoModeWithSystemTheme];
724 return zoom_decoration_->UpdateIfNecessary( 784 return zoom_decoration_->UpdateIfNecessary(
725 ui_zoom::ZoomController::FromWebContents(web_contents), 785 ui_zoom::ZoomController::FromWebContents(web_contents),
726 default_zoom_changed); 786 default_zoom_changed,
787 inDarkMode);
727 } 788 }
728 789
729 void LocationBarViewMac::OnDefaultZoomLevelChanged() { 790 void LocationBarViewMac::OnDefaultZoomLevelChanged() {
730 if (UpdateZoomDecoration(/*default_zoom_changed=*/true)) 791 if (UpdateZoomDecoration(/*default_zoom_changed=*/true))
731 OnDecorationsChanged(); 792 OnDecorationsChanged();
732 } 793 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698