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

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: Fix issue from browser test. 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 // Convert to the device color space before getting the SkColor.
573 textColor = [textColor colorUsingColorSpaceName:NSDeviceRGBColorSpace];
574 vectorIconColor = skia::NSDeviceColorToSkColor(textColor);
575 }
576 }
577
578 DCHECK(vectorIconId != gfx::VectorIconId::VECTOR_ICON_NONE);
579 NSImage* image = NSImageFromImageSkia(gfx::CreateVectorIcon(
580 vectorIconId, kIconSize, vectorIconColor));
581
553 location_icon_decoration_->SetImage(image); 582 location_icon_decoration_->SetImage(image);
554 ev_bubble_decoration_->SetImage(image); 583 ev_bubble_decoration_->SetImage(image);
584
555 Layout(); 585 Layout();
586 }
556 587
557 // Make sure we're displaying the correct icon color for a dark location bar. 588 void LocationBarViewMac::OnAddedToWindow() {
589 if (!ui::MaterialDesignController::IsModeMaterial()) {
590 return;
591 }
592
593 // Update the location-bar icon.
594 UpdateLocationIcon();
595
596 // Make sure we're displaying the correct star color for a dark location bar.
558 if ([[field_ window] inIncognitoModeWithSystemTheme]) { 597 if ([[field_ window] inIncognitoModeWithSystemTheme]) {
559 star_decoration_->SetStarred(star_decoration_->starred(), true); 598 star_decoration_->SetStarred(star_decoration_->starred(), true);
560 } 599 }
561 } 600 }
562 601
602 void LocationBarViewMac::OnChanged() {
603 NSImage* image = nil;
604 if (ui::MaterialDesignController::IsModeMaterial()) {
605 UpdateLocationIcon();
606 } else {
607 const int resource_id = omnibox_view_->GetIcon();
608 image = OmniboxViewMac::ImageForResource(resource_id);
609 location_icon_decoration_->SetImage(image);
610 ev_bubble_decoration_->SetImage(image);
611 Layout();
612 }
613 }
614
563 void LocationBarViewMac::OnSetFocus() { 615 void LocationBarViewMac::OnSetFocus() {
564 // Update the keyword and search hint states. 616 // Update the keyword and search hint states.
565 OnChanged(); 617 OnChanged();
566 } 618 }
567 619
568 void LocationBarViewMac::ShowURL() { 620 void LocationBarViewMac::ShowURL() {
569 omnibox_view_->ShowURL(); 621 omnibox_view_->ShowURL();
570 } 622 }
571 623
572 ToolbarModel* LocationBarViewMac::GetToolbarModel() { 624 ToolbarModel* LocationBarViewMac::GetToolbarModel() {
573 return browser_->toolbar_model(); 625 return browser_->toolbar_model();
574 } 626 }
575 627
576 const ToolbarModel* LocationBarViewMac::GetToolbarModel() const { 628 const ToolbarModel* LocationBarViewMac::GetToolbarModel() const {
577 return browser_->toolbar_model(); 629 return browser_->toolbar_model();
578 } 630 }
579 631
580 WebContents* LocationBarViewMac::GetWebContents() { 632 WebContents* LocationBarViewMac::GetWebContents() {
581 return browser_->tab_strip_model()->GetActiveWebContents(); 633 return browser_->tab_strip_model()->GetActiveWebContents();
582 } 634 }
583 635
636 bool LocationBarViewMac::ShouldShowEVBubble() const {
637 return (GetToolbarModel()->GetSecurityLevel(false) ==
638 security_state::SecurityStateModel::EV_SECURE);
639 }
640
584 NSImage* LocationBarViewMac::GetKeywordImage(const base::string16& keyword) { 641 NSImage* LocationBarViewMac::GetKeywordImage(const base::string16& keyword) {
585 const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile( 642 const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile(
586 profile())->GetTemplateURLForKeyword(keyword); 643 profile())->GetTemplateURLForKeyword(keyword);
587 if (template_url && 644 if (template_url &&
588 (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) { 645 (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) {
589 return extensions::OmniboxAPI::Get(profile())-> 646 return extensions::OmniboxAPI::Get(profile())->
590 GetOmniboxIcon(template_url->GetExtensionId()).AsNSImage(); 647 GetOmniboxIcon(template_url->GetExtensionId()).AsNSImage();
591 } 648 }
592 649
593 return OmniboxViewMac::ImageForResource(IDR_OMNIBOX_SEARCH); 650 return ui::MaterialDesignController::IsModeMaterial()
651 ? NSImageFromImageSkia(gfx::CreateVectorIcon(
652 gfx::VectorIconId::OMNIBOX_SEARCH, 16, gfx::kGoogleBlue700))
653 : OmniboxViewMac::ImageForResource(IDR_OMNIBOX_SEARCH);
594 } 654 }
595 655
596 void LocationBarViewMac::PostNotification(NSString* notification) { 656 void LocationBarViewMac::PostNotification(NSString* notification) {
597 [[NSNotificationCenter defaultCenter] postNotificationName:notification 657 [[NSNotificationCenter defaultCenter] postNotificationName:notification
598 object:[NSValue valueWithPointer:this]]; 658 object:[NSValue valueWithPointer:this]];
599 } 659 }
600 660
601 PageActionDecoration* LocationBarViewMac::GetPageActionDecoration( 661 PageActionDecoration* LocationBarViewMac::GetPageActionDecoration(
602 ExtensionAction* page_action) { 662 ExtensionAction* page_action) {
603 DCHECK(page_action); 663 DCHECK(page_action);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 return; 766 return;
707 767
708 WebContents* web_contents = GetWebContents(); 768 WebContents* web_contents = GetWebContents();
709 if (!web_contents) 769 if (!web_contents)
710 return; 770 return;
711 translate::LanguageState& language_state = 771 translate::LanguageState& language_state =
712 ChromeTranslateClient::FromWebContents(web_contents)->GetLanguageState(); 772 ChromeTranslateClient::FromWebContents(web_contents)->GetLanguageState();
713 bool enabled = language_state.translate_enabled(); 773 bool enabled = language_state.translate_enabled();
714 command_updater()->UpdateCommandEnabled(IDC_TRANSLATE_PAGE, enabled); 774 command_updater()->UpdateCommandEnabled(IDC_TRANSLATE_PAGE, enabled);
715 translate_decoration_->SetVisible(enabled); 775 translate_decoration_->SetVisible(enabled);
716 translate_decoration_->SetLit(language_state.IsPageTranslated()); 776 bool inDarkMode = [[field_ window] inIncognitoModeWithSystemTheme];
777 translate_decoration_->SetLit(language_state.IsPageTranslated(), inDarkMode);
717 } 778 }
718 779
719 bool LocationBarViewMac::UpdateZoomDecoration(bool default_zoom_changed) { 780 bool LocationBarViewMac::UpdateZoomDecoration(bool default_zoom_changed) {
720 WebContents* web_contents = GetWebContents(); 781 WebContents* web_contents = GetWebContents();
721 if (!web_contents) 782 if (!web_contents)
722 return false; 783 return false;
723 784
785 bool inDarkMode = [[field_ window] inIncognitoModeWithSystemTheme];
724 return zoom_decoration_->UpdateIfNecessary( 786 return zoom_decoration_->UpdateIfNecessary(
725 ui_zoom::ZoomController::FromWebContents(web_contents), 787 ui_zoom::ZoomController::FromWebContents(web_contents),
726 default_zoom_changed); 788 default_zoom_changed,
789 inDarkMode);
727 } 790 }
728 791
729 void LocationBarViewMac::OnDefaultZoomLevelChanged() { 792 void LocationBarViewMac::OnDefaultZoomLevelChanged() {
730 if (UpdateZoomDecoration(/*default_zoom_changed=*/true)) 793 if (UpdateZoomDecoration(/*default_zoom_changed=*/true))
731 OnDecorationsChanged(); 794 OnDecorationsChanged();
732 } 795 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698