Chromium Code Reviews| 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 81d7668b84f7c13a8fa018b7d7b75a3d88c1e196..e115482755dd4468b1c81796db7abeed04f3a536 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 |
| @@ -34,7 +34,6 @@ |
| #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" |
| #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" |
| #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h" |
| -#import "chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.h" |
| #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h" |
| #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h" |
| #import "chrome/browser/ui/cocoa/location_bar/manage_passwords_decoration.h" |
| @@ -43,6 +42,7 @@ |
| #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" |
| #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" |
| #import "chrome/browser/ui/cocoa/location_bar/translate_decoration.h" |
| +#import "chrome/browser/ui/cocoa/location_bar/verbose_state_bubble_decoration.h" |
| #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h" |
| #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" |
| #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
| @@ -57,7 +57,6 @@ |
| #include "components/prefs/pref_service.h" |
| #include "components/search_engines/template_url.h" |
| #include "components/search_engines/template_url_service.h" |
| -#include "components/security_state/security_state_model.h" |
| #include "components/translate/core/browser/language_state.h" |
| #include "components/zoom/zoom_controller.h" |
| #include "components/zoom/zoom_event_manager.h" |
| @@ -87,6 +86,9 @@ const static int kFirstRunBubbleYOffset = 1; |
| const int kDefaultIconSize = 16; |
| +// The minimum width the URL should have for the verbose state to be shown. |
| +const int kMinURLWidth = 120; |
| + |
| // Color of the vector graphic icons when the location bar is dark. |
| // SkColorSetARGB(0xCC, 0xFF, 0xFF 0xFF); |
| const SkColor kMaterialDarkVectorIconColor = SK_ColorWHITE; |
| @@ -106,8 +108,9 @@ LocationBarViewMac::LocationBarViewMac(AutocompleteTextField* field, |
| field_(field), |
| location_icon_decoration_(new LocationIconDecoration(this)), |
| selected_keyword_decoration_(new SelectedKeywordDecoration()), |
| - ev_bubble_decoration_( |
| - new EVBubbleDecoration(location_icon_decoration_.get())), |
| + verbose_state_bubble_decoration_( |
| + new VerboseStateBubbleDecoration(location_icon_decoration_.get(), |
| + this)), |
| save_credit_card_decoration_( |
| new SaveCreditCardDecoration(command_updater)), |
| star_decoration_(new StarDecoration(command_updater)), |
| @@ -392,8 +395,9 @@ NSPoint LocationBarViewMac::GetManagePasswordsBubblePoint() const { |
| } |
| NSPoint LocationBarViewMac::GetPageInfoBubblePoint() const { |
| - if (ev_bubble_decoration_->IsVisible()) { |
| - return [field_ bubblePointForDecoration:ev_bubble_decoration_.get()]; |
| + if (verbose_state_bubble_decoration_->IsVisible()) { |
| + return [field_ |
| + bubblePointForDecoration:verbose_state_bubble_decoration_.get()]; |
| } else { |
| return [field_ bubblePointForDecoration:location_icon_decoration_.get()]; |
| } |
| @@ -422,7 +426,7 @@ void LocationBarViewMac::Layout() { |
| [cell clearDecorations]; |
| [cell addLeftDecoration:location_icon_decoration_.get()]; |
| [cell addLeftDecoration:selected_keyword_decoration_.get()]; |
| - [cell addLeftDecoration:ev_bubble_decoration_.get()]; |
| + [cell addLeftDecoration:verbose_state_bubble_decoration_.get()]; |
| [cell addRightDecoration:star_decoration_.get()]; |
| [cell addRightDecoration:translate_decoration_.get()]; |
| [cell addRightDecoration:zoom_decoration_.get()]; |
| @@ -445,9 +449,13 @@ void LocationBarViewMac::Layout() { |
| // By default only the location icon is visible. |
| location_icon_decoration_->SetVisible(true); |
| selected_keyword_decoration_->SetVisible(false); |
| - ev_bubble_decoration_->SetVisible(false); |
| keyword_hint_decoration_->SetVisible(false); |
| + if (omnibox_view_->IsEditingOrEmpty()) |
| + verbose_state_bubble_decoration_->ResetAndHide(); |
| + else |
| + verbose_state_bubble_decoration_->SetVisible(false); |
| + |
| // Get the keyword to use for keyword-search and hinting. |
| const base::string16 keyword = omnibox_view_->model()->keyword(); |
| base::string16 short_name; |
| @@ -468,17 +476,40 @@ void LocationBarViewMac::Layout() { |
| // Design we need to set its color, which we cannot do until we know the |
| // theme (by being installed in a browser window). |
| selected_keyword_decoration_->SetImage(GetKeywordImage(keyword)); |
| + } else if (!keyword.empty() && is_keyword_hint) { |
| + keyword_hint_decoration_->SetKeyword(short_name, is_extension_keyword); |
| + keyword_hint_decoration_->SetVisible(true); |
| } else if (ShouldShowEVBubble()) { |
| // Switch from location icon to show the EV bubble instead. |
| location_icon_decoration_->SetVisible(false); |
| - ev_bubble_decoration_->SetVisible(true); |
| + verbose_state_bubble_decoration_->SetVisible(true); |
| base::string16 label(GetToolbarModel()->GetEVCertName()); |
| - ev_bubble_decoration_->SetFullLabel(base::SysUTF16ToNSString(label)); |
| - } else if (!keyword.empty() && is_keyword_hint) { |
| - keyword_hint_decoration_->SetKeyword(short_name, |
| - is_extension_keyword); |
| - keyword_hint_decoration_->SetVisible(true); |
| + verbose_state_bubble_decoration_->SetFullLabel( |
| + base::SysUTF16ToNSString(label)); |
| + } else if (ShouldShowVerboseState()) { |
| + bool is_verbose_visible = true; |
| + CGFloat available_width = |
| + [cell availableWidthInFrame:[[cell controlView] frame]]; |
| + |
| + // If there's not enough space, animate out the verbose. If show the |
| + // verbose until is has finished animating out. |
| + if (available_width < kMinURLWidth) { |
| + is_verbose_visible = verbose_state_bubble_decoration_->AnimatingOut(); |
| + if (verbose_state_bubble_decoration_->HasAnimatedIn()) |
| + verbose_state_bubble_decoration_->AnimateOut(); |
| + } |
| + |
| + // Don't change the label if the verbose is in the process of animating |
| + // out the old one. |
| + base::string16 label(GetToolbarModel()->GetVerboseStateText()); |
| + if (!verbose_state_bubble_decoration_->AnimatingOut()) { |
| + verbose_state_bubble_decoration_->SetFullLabel( |
| + base::SysUTF16ToNSString(label)); |
| + } |
| + |
| + location_icon_decoration_->SetVisible(!is_verbose_visible); |
| + verbose_state_bubble_decoration_->SetVisible(is_verbose_visible); |
| } |
| // These need to change anytime the layout changes. |
| @@ -567,32 +598,10 @@ void LocationBarViewMac::UpdateWithoutTabRestore() { |
| } |
| void LocationBarViewMac::UpdateLocationIcon() { |
| - bool in_dark_mode = IsLocationBarDark(); |
| - |
| - SkColor vector_icon_color = gfx::kPlaceholderColor; |
| - gfx::VectorIconId vector_icon_id = gfx::VectorIconId::VECTOR_ICON_NONE; |
| - if (ShouldShowEVBubble()) { |
| - vector_icon_id = gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID; |
| - vector_icon_color = gfx::kGoogleGreen700; |
| - } else { |
| - vector_icon_id = omnibox_view_->GetVectorIcon(); |
| - security_state::SecurityStateModel::SecurityLevel security_level = |
| - GetToolbarModel()->GetSecurityLevel(false); |
| - if (security_level == security_state::SecurityStateModel::NONE) { |
| - vector_icon_color = gfx::kChromeIconGrey; |
| - } else { |
| - NSColor* sRGBColor = |
| - OmniboxViewMac::GetSecureTextColor(security_level, in_dark_mode); |
| - NSColor* deviceColor = |
| - [sRGBColor colorUsingColorSpace:[NSColorSpace deviceRGBColorSpace]]; |
| - vector_icon_color = skia::NSDeviceColorToSkColor(deviceColor); |
| - } |
| - } |
| - |
| - // If the theme is dark, then the color should always be |
| - // kMaterialDarkVectorIconColor. |
| - if (in_dark_mode) |
| - vector_icon_color = kMaterialDarkVectorIconColor; |
| + SkColor vector_icon_color = GetLocationBarIconColor(); |
| + gfx::VectorIconId vector_icon_id = |
| + ShouldShowEVBubble() ? gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID |
| + : omnibox_view_->GetVectorIcon(); |
| DCHECK(vector_icon_id != gfx::VectorIconId::VECTOR_ICON_NONE); |
| NSImage* image = NSImageFromImageSkiaWithColorSpace( |
| @@ -600,8 +609,29 @@ void LocationBarViewMac::UpdateLocationIcon() { |
| vector_icon_color), |
| base::mac::GetSRGBColorSpace()); |
| location_icon_decoration_->SetImage(image); |
| - ev_bubble_decoration_->SetImage(image); |
| + verbose_state_bubble_decoration_->SetImage(image); |
| + verbose_state_bubble_decoration_->SetLabelColor(vector_icon_color); |
| + |
| Layout(); |
| + |
| + // If the security level has changed, check if the verbose needs to be |
|
Robert Sesek
2016/08/16 22:25:32
"check if the verbose" ... verbose what?
spqchan
2016/08/17 00:41:18
Done.
|
| + // animated. If we need to show it, animate it in. Otherwise, animate it out |
| + // if it's already fully displayed. |
| + security_state::SecurityStateModel::SecurityLevel current_security = |
|
Robert Sesek
2016/08/16 22:25:32
naming: new_security_level ? looking at |security_
spqchan
2016/08/17 00:41:18
Done.
|
| + GetToolbarModel()->GetSecurityLevel(false); |
| + bool is_secure_to_secure = IsSecureConnection(current_security) && |
| + IsSecureConnection(security_level_); |
| + if (security_level_ != current_security && !is_secure_to_secure) { |
| + if (ShouldShowVerboseState()) |
| + verbose_state_bubble_decoration_->AnimateIn(); |
| + else if (verbose_state_bubble_decoration_->HasAnimatedIn()) |
| + verbose_state_bubble_decoration_->AnimateOut(); |
| + } else if (verbose_state_bubble_decoration_->HasAnimatedOut()) { |
| + // Animate the verbose back in if it was animated out. |
| + if (ShouldShowVerboseState()) |
| + verbose_state_bubble_decoration_->AnimateIn(false); |
| + } |
| + security_level_ = GetToolbarModel()->GetSecurityLevel(false); |
| } |
| void LocationBarViewMac::UpdateColorsToMatchTheme() { |
| @@ -636,7 +666,7 @@ void LocationBarViewMac::OnChanged() { |
| const int resource_id = omnibox_view_->GetIcon(); |
| NSImage* image = OmniboxViewMac::ImageForResource(resource_id); |
| location_icon_decoration_->SetImage(image); |
| - ev_bubble_decoration_->SetImage(image); |
| + verbose_state_bubble_decoration_->SetImage(image); |
| Layout(); |
| return; |
| } |
| @@ -664,6 +694,20 @@ bool LocationBarViewMac::ShouldShowEVBubble() const { |
| security_state::SecurityStateModel::EV_SECURE); |
| } |
| +bool LocationBarViewMac::ShouldShowVerboseState() const { |
| + security_state::SecurityStateModel::SecurityLevel security = |
| + GetToolbarModel()->GetSecurityLevel(false); |
| + bool has_verbose_for_security = |
| + IsSecureConnection(security) || |
| + security == security_state::SecurityStateModel::SECURITY_ERROR; |
| + |
| + return ui::MaterialDesignController::IsModeMaterial() && |
| + (has_verbose_for_security || |
| + verbose_state_bubble_decoration_->AnimatingOut()) && |
| + !omnibox_view_->IsEditingOrEmpty() && |
| + !omnibox_view_->model()->is_keyword_hint(); |
| +} |
| + |
| bool LocationBarViewMac::IsLocationBarDark() const { |
| return [[field_ window] inIncognitoModeWithSystemTheme]; |
| } |
| @@ -689,6 +733,27 @@ NSImage* LocationBarViewMac::GetKeywordImage(const base::string16& keyword) { |
| return OmniboxViewMac::ImageForResource(IDR_OMNIBOX_SEARCH); |
| } |
| +SkColor LocationBarViewMac::GetLocationBarIconColor() const { |
| + bool in_dark_mode = IsLocationBarDark(); |
| + if (in_dark_mode) |
| + return kMaterialDarkVectorIconColor; |
| + |
| + if (ShouldShowEVBubble()) |
| + return gfx::kGoogleGreen700; |
| + |
| + security_state::SecurityStateModel::SecurityLevel security_level = |
| + GetToolbarModel()->GetSecurityLevel(false); |
| + |
| + if (security_level == security_state::SecurityStateModel::NONE) |
| + return gfx::kChromeIconGrey; |
| + |
| + NSColor* sRGBColor = |
|
Robert Sesek
2016/08/16 22:25:32
naming: use under_scores, and below
spqchan
2016/08/17 00:41:18
Done.
|
| + OmniboxViewMac::GetSecureTextColor(security_level, in_dark_mode); |
| + NSColor* deviceColor = |
| + [sRGBColor colorUsingColorSpace:[NSColorSpace deviceRGBColorSpace]]; |
| + return skia::NSDeviceColorToSkColor(deviceColor); |
| +} |
| + |
| void LocationBarViewMac::PostNotification(NSString* notification) { |
| [[NSNotificationCenter defaultCenter] postNotificationName:notification |
| object:[NSValue valueWithPointer:this]]; |
| @@ -823,6 +888,12 @@ bool LocationBarViewMac::UpdateZoomDecoration(bool default_zoom_changed) { |
| IsLocationBarDark()); |
| } |
| +bool LocationBarViewMac::IsSecureConnection( |
| + security_state::SecurityStateModel::SecurityLevel level) const { |
| + return level == security_state::SecurityStateModel::SECURE || |
| + level == security_state::SecurityStateModel::EV_SECURE; |
| +} |
| + |
| void LocationBarViewMac::UpdateAccessibilityViewPosition( |
| LocationBarDecoration* decoration) { |
| if (!decoration->IsVisible()) |
| @@ -839,7 +910,7 @@ std::vector<LocationBarDecoration*> LocationBarViewMac::GetDecorations() { |
| // are page actions and the keyword hint. |
| decorations.push_back(location_icon_decoration_.get()); |
| decorations.push_back(selected_keyword_decoration_.get()); |
| - decorations.push_back(ev_bubble_decoration_.get()); |
| + decorations.push_back(verbose_state_bubble_decoration_.get()); |
| decorations.push_back(save_credit_card_decoration_.get()); |
| decorations.push_back(star_decoration_.get()); |
| decorations.push_back(translate_decoration_.get()); |