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 51cd76b21ea029194d92021ca983ca0c596b240c..eda3e577d76b224b4d1e2206011e1321879afb14 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 |
@@ -40,6 +40,7 @@ |
#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" |
+#import "chrome/browser/ui/cocoa/location_bar/mic_search_decoration.h" |
#import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h" |
#import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" |
#import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" |
@@ -101,6 +102,7 @@ |
translate_decoration_(new TranslateDecoration(command_updater)), |
zoom_decoration_(new ZoomDecoration(this)), |
keyword_hint_decoration_(new KeywordHintDecoration()), |
+ mic_search_decoration_(new MicSearchDecoration(command_updater)), |
manage_passwords_decoration_( |
new ManagePasswordsDecoration(command_updater, this)), |
browser_(browser), |
@@ -117,6 +119,8 @@ |
base::Bind(&LocationBarViewMac::OnEditBookmarksEnabledChanged, |
base::Unretained(this))); |
+ browser_->search_model()->AddObserver(this); |
+ |
ui_zoom::ZoomEventManager::GetForBrowserContext(profile) |
->AddZoomEventManagerObserver(this); |
@@ -132,6 +136,7 @@ |
// Disconnect from cell in case it outlives us. |
[[field_ cell] clearDecorations]; |
+ browser_->search_model()->RemoveObserver(this); |
ui_zoom::ZoomEventManager::GetForBrowserContext(profile()) |
->RemoveZoomEventManagerObserver(this); |
} |
@@ -405,6 +410,7 @@ |
} |
[cell addRightDecoration:keyword_hint_decoration_.get()]; |
+ [cell addRightDecoration:mic_search_decoration_.get()]; |
// By default only the location icon is visible. |
location_icon_decoration_->SetVisible(true); |
@@ -517,6 +523,7 @@ |
UpdateZoomDecoration(/*default_zoom_changed=*/false); |
RefreshPageActionDecorations(); |
RefreshContentSettingsDecorations(); |
+ UpdateMicSearchDecorationVisibility(); |
if (contents) |
omnibox_view_->OnTabChanged(contents); |
else |
@@ -575,6 +582,12 @@ |
} |
return OmniboxViewMac::ImageForResource(IDR_OMNIBOX_SEARCH); |
+} |
+ |
+void LocationBarViewMac::ModelChanged(const SearchModel::State& old_state, |
+ const SearchModel::State& new_state) { |
+ if (UpdateMicSearchDecorationVisibility()) |
+ Layout(); |
} |
void LocationBarViewMac::PostNotification(NSString* notification) { |
@@ -714,3 +727,12 @@ |
if (UpdateZoomDecoration(/*default_zoom_changed=*/true)) |
OnDecorationsChanged(); |
} |
+ |
+bool LocationBarViewMac::UpdateMicSearchDecorationVisibility() { |
+ bool is_visible = !GetToolbarModel()->input_in_progress() && |
+ browser_->search_model()->voice_search_supported(); |
+ if (mic_search_decoration_->IsVisible() == is_visible) |
+ return false; |
+ mic_search_decoration_->SetVisible(is_visible); |
+ return true; |
+} |