Index: chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm |
diff --git a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm |
index 6f9d9b5464a1fd6894aa423f60366e979b0c0828..bc3aeeb1ac6fd54b01e7299f60967eb0e28d6767 100644 |
--- a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm |
+++ b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm |
@@ -67,7 +67,13 @@ |
#include "skia/ext/skia_utils_mac.h" |
#import "ui/base/cocoa/cocoa_base_utils.h" |
#include "ui/base/l10n/l10n_util_mac.h" |
+#include "ui/base/material_design/material_design_controller.h" |
+#include "ui/gfx/color_palette.h" |
+#include "ui/gfx/color_utils.h" |
#include "ui/gfx/image/image.h" |
+#include "ui/gfx/image/image_skia_util_mac.h" |
+#include "ui/gfx/paint_vector_icon.h" |
+#include "ui/gfx/vector_icons_public.h" |
using content::WebContents; |
@@ -197,6 +203,8 @@ void LocationBarViewMac::UpdateSaveCreditCardIcon() { |
bool enabled = controller && controller->IsIconVisible(); |
command_updater()->UpdateCommandEnabled(IDC_SAVE_CREDIT_CARD_FOR_PAGE, |
enabled); |
+ bool inDarkMode = [[field_ window] inIncognitoModeWithSystemTheme]; |
+ save_credit_card_decoration_->SetIcon(inDarkMode); |
save_credit_card_decoration_->SetVisible(enabled); |
OnDecorationsChanged(); |
} |
@@ -339,7 +347,8 @@ void LocationBarViewMac::SetStarred(bool starred) { |
} |
void LocationBarViewMac::SetTranslateIconLit(bool on) { |
- translate_decoration_->SetLit(on); |
+ bool inDarkMode = [[field_ window] inIncognitoModeWithSystemTheme]; |
+ translate_decoration_->SetLit(on, inDarkMode); |
OnDecorationsChanged(); |
} |
@@ -447,8 +456,7 @@ void LocationBarViewMac::Layout() { |
selected_keyword_decoration_->SetVisible(true); |
selected_keyword_decoration_->SetKeyword(short_name, is_extension_keyword); |
selected_keyword_decoration_->SetImage(GetKeywordImage(keyword)); |
- } else if (GetToolbarModel()->GetSecurityLevel(false) == |
- security_state::SecurityStateModel::EV_SECURE) { |
+ } else if (ShouldShowEVBubble()) { |
// Switch from location icon to show the EV bubble instead. |
location_icon_decoration_->SetVisible(false); |
ev_bubble_decoration_->SetVisible(true); |
@@ -546,20 +554,64 @@ void LocationBarViewMac::UpdateWithoutTabRestore() { |
Update(nullptr); |
} |
-void LocationBarViewMac::OnChanged() { |
- // Update the location-bar icon. |
- const int resource_id = omnibox_view_->GetIcon(); |
- NSImage* image = OmniboxViewMac::ImageForResource(resource_id); |
+void LocationBarViewMac::UpdateLocationIcon() { |
+ bool inDarkMode = [[field_ window] inIncognitoModeWithSystemTheme]; |
+ |
+ SkColor vectorIconColor = gfx::kPlaceholderColor; |
+ gfx::VectorIconId vectorIconId = gfx::VectorIconId::VECTOR_ICON_NONE; |
+ const int kIconSize = 16; |
+ if (ShouldShowEVBubble()) { |
+ vectorIconId = gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID_IN_CHIP; |
+ vectorIconColor = gfx::kGoogleGreen700; |
+ } else { |
+ vectorIconId = omnibox_view_->GetVectorIcon(inDarkMode); |
+ if (inDarkMode) { |
+ vectorIconColor = SK_ColorWHITE; |
+ } else { |
+ NSColor* textColor = OmniboxViewMac::BaseTextColor(inDarkMode); |
+ // Convert to the device color space before getting the SkColor. |
+ textColor = [textColor colorUsingColorSpaceName:NSDeviceRGBColorSpace]; |
+ vectorIconColor = skia::NSDeviceColorToSkColor(textColor); |
+ } |
+ } |
+ |
+ DCHECK(vectorIconId != gfx::VectorIconId::VECTOR_ICON_NONE); |
+ NSImage* image = NSImageFromImageSkia(gfx::CreateVectorIcon( |
+ vectorIconId, kIconSize, vectorIconColor)); |
+ |
location_icon_decoration_->SetImage(image); |
ev_bubble_decoration_->SetImage(image); |
+ |
Layout(); |
+} |
+ |
+void LocationBarViewMac::OnAddedToWindow() { |
+ if (!ui::MaterialDesignController::IsModeMaterial()) { |
+ return; |
+ } |
+ |
+ // Update the location-bar icon. |
+ UpdateLocationIcon(); |
- // Make sure we're displaying the correct icon color for a dark location bar. |
+ // Make sure we're displaying the correct star color for a dark location bar. |
if ([[field_ window] inIncognitoModeWithSystemTheme]) { |
star_decoration_->SetStarred(star_decoration_->starred(), true); |
} |
} |
+void LocationBarViewMac::OnChanged() { |
+ NSImage* image = nil; |
+ if (ui::MaterialDesignController::IsModeMaterial()) { |
+ UpdateLocationIcon(); |
+ } else { |
+ const int resource_id = omnibox_view_->GetIcon(); |
+ image = OmniboxViewMac::ImageForResource(resource_id); |
+ location_icon_decoration_->SetImage(image); |
+ ev_bubble_decoration_->SetImage(image); |
+ Layout(); |
+ } |
+} |
+ |
void LocationBarViewMac::OnSetFocus() { |
// Update the keyword and search hint states. |
OnChanged(); |
@@ -581,6 +633,11 @@ WebContents* LocationBarViewMac::GetWebContents() { |
return browser_->tab_strip_model()->GetActiveWebContents(); |
} |
+bool LocationBarViewMac::ShouldShowEVBubble() const { |
+ return (GetToolbarModel()->GetSecurityLevel(false) == |
+ security_state::SecurityStateModel::EV_SECURE); |
+} |
+ |
NSImage* LocationBarViewMac::GetKeywordImage(const base::string16& keyword) { |
const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile( |
profile())->GetTemplateURLForKeyword(keyword); |
@@ -590,7 +647,10 @@ NSImage* LocationBarViewMac::GetKeywordImage(const base::string16& keyword) { |
GetOmniboxIcon(template_url->GetExtensionId()).AsNSImage(); |
} |
- return OmniboxViewMac::ImageForResource(IDR_OMNIBOX_SEARCH); |
+ return ui::MaterialDesignController::IsModeMaterial() |
+ ? NSImageFromImageSkia(gfx::CreateVectorIcon( |
+ gfx::VectorIconId::OMNIBOX_SEARCH, 16, gfx::kGoogleBlue700)) |
+ : OmniboxViewMac::ImageForResource(IDR_OMNIBOX_SEARCH); |
} |
void LocationBarViewMac::PostNotification(NSString* notification) { |
@@ -713,7 +773,8 @@ void LocationBarViewMac::UpdateTranslateDecoration() { |
bool enabled = language_state.translate_enabled(); |
command_updater()->UpdateCommandEnabled(IDC_TRANSLATE_PAGE, enabled); |
translate_decoration_->SetVisible(enabled); |
- translate_decoration_->SetLit(language_state.IsPageTranslated()); |
+ bool inDarkMode = [[field_ window] inIncognitoModeWithSystemTheme]; |
+ translate_decoration_->SetLit(language_state.IsPageTranslated(), inDarkMode); |
} |
bool LocationBarViewMac::UpdateZoomDecoration(bool default_zoom_changed) { |
@@ -721,9 +782,11 @@ bool LocationBarViewMac::UpdateZoomDecoration(bool default_zoom_changed) { |
if (!web_contents) |
return false; |
+ bool inDarkMode = [[field_ window] inIncognitoModeWithSystemTheme]; |
return zoom_decoration_->UpdateIfNecessary( |
ui_zoom::ZoomController::FromWebContents(web_contents), |
- default_zoom_changed); |
+ default_zoom_changed, |
+ inDarkMode); |
} |
void LocationBarViewMac::OnDefaultZoomLevelChanged() { |