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

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

Issue 1436583002: Revert of Remove setVoiceSearchSupported part of EmbeddedSearch SearchBox API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 22 matching lines...) Expand all
33 #import "chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.h " 33 #import "chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.h "
34 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" 34 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h"
35 #import "chrome/browser/ui/cocoa/first_run_bubble_controller.h" 35 #import "chrome/browser/ui/cocoa/first_run_bubble_controller.h"
36 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" 36 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h"
37 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" 37 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h"
38 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h" 38 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h"
39 #import "chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.h" 39 #import "chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.h"
40 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h" 40 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h"
41 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h" 41 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h"
42 #import "chrome/browser/ui/cocoa/location_bar/manage_passwords_decoration.h" 42 #import "chrome/browser/ui/cocoa/location_bar/manage_passwords_decoration.h"
43 #import "chrome/browser/ui/cocoa/location_bar/mic_search_decoration.h"
43 #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h" 44 #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h"
44 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" 45 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h"
45 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" 46 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h"
46 #import "chrome/browser/ui/cocoa/location_bar/translate_decoration.h" 47 #import "chrome/browser/ui/cocoa/location_bar/translate_decoration.h"
47 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h" 48 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h"
48 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" 49 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
49 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" 50 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
50 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" 51 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
51 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" 52 #include "chrome/browser/ui/content_settings/content_setting_image_model.h"
52 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" 53 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 omnibox_view_(new OmniboxViewMac(this, profile, command_updater, field)), 95 omnibox_view_(new OmniboxViewMac(this, profile, command_updater, field)),
95 field_(field), 96 field_(field),
96 location_icon_decoration_(new LocationIconDecoration(this)), 97 location_icon_decoration_(new LocationIconDecoration(this)),
97 selected_keyword_decoration_(new SelectedKeywordDecoration()), 98 selected_keyword_decoration_(new SelectedKeywordDecoration()),
98 ev_bubble_decoration_( 99 ev_bubble_decoration_(
99 new EVBubbleDecoration(location_icon_decoration_.get())), 100 new EVBubbleDecoration(location_icon_decoration_.get())),
100 star_decoration_(new StarDecoration(command_updater)), 101 star_decoration_(new StarDecoration(command_updater)),
101 translate_decoration_(new TranslateDecoration(command_updater)), 102 translate_decoration_(new TranslateDecoration(command_updater)),
102 zoom_decoration_(new ZoomDecoration(this)), 103 zoom_decoration_(new ZoomDecoration(this)),
103 keyword_hint_decoration_(new KeywordHintDecoration()), 104 keyword_hint_decoration_(new KeywordHintDecoration()),
105 mic_search_decoration_(new MicSearchDecoration(command_updater)),
104 manage_passwords_decoration_( 106 manage_passwords_decoration_(
105 new ManagePasswordsDecoration(command_updater, this)), 107 new ManagePasswordsDecoration(command_updater, this)),
106 browser_(browser), 108 browser_(browser),
107 location_bar_visible_(true), 109 location_bar_visible_(true),
108 weak_ptr_factory_(this) { 110 weak_ptr_factory_(this) {
109 for (ContentSettingsType type : 111 for (ContentSettingsType type :
110 ContentSettingBubbleModel::GetSupportedBubbleTypes()) { 112 ContentSettingBubbleModel::GetSupportedBubbleTypes()) {
111 content_setting_decorations_.push_back( 113 content_setting_decorations_.push_back(
112 new ContentSettingDecoration(type, this, profile)); 114 new ContentSettingDecoration(type, this, profile));
113 } 115 }
114 116
115 edit_bookmarks_enabled_.Init( 117 edit_bookmarks_enabled_.Init(
116 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(), 118 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(),
117 base::Bind(&LocationBarViewMac::OnEditBookmarksEnabledChanged, 119 base::Bind(&LocationBarViewMac::OnEditBookmarksEnabledChanged,
118 base::Unretained(this))); 120 base::Unretained(this)));
119 121
122 browser_->search_model()->AddObserver(this);
123
120 ui_zoom::ZoomEventManager::GetForBrowserContext(profile) 124 ui_zoom::ZoomEventManager::GetForBrowserContext(profile)
121 ->AddZoomEventManagerObserver(this); 125 ->AddZoomEventManagerObserver(this);
122 126
123 [[field_ cell] setIsPopupMode: 127 [[field_ cell] setIsPopupMode:
124 !browser->SupportsWindowFeature(Browser::FEATURE_TABSTRIP)]; 128 !browser->SupportsWindowFeature(Browser::FEATURE_TABSTRIP)];
125 129
126 // Sets images for the decorations, and performs a layout. This call ensures 130 // Sets images for the decorations, and performs a layout. This call ensures
127 // that this class is in a consistent state after initialization. 131 // that this class is in a consistent state after initialization.
128 OnChanged(); 132 OnChanged();
129 } 133 }
130 134
131 LocationBarViewMac::~LocationBarViewMac() { 135 LocationBarViewMac::~LocationBarViewMac() {
132 // Disconnect from cell in case it outlives us. 136 // Disconnect from cell in case it outlives us.
133 [[field_ cell] clearDecorations]; 137 [[field_ cell] clearDecorations];
134 138
139 browser_->search_model()->RemoveObserver(this);
135 ui_zoom::ZoomEventManager::GetForBrowserContext(profile()) 140 ui_zoom::ZoomEventManager::GetForBrowserContext(profile())
136 ->RemoveZoomEventManagerObserver(this); 141 ->RemoveZoomEventManagerObserver(this);
137 } 142 }
138 143
139 void LocationBarViewMac::ShowFirstRunBubble() { 144 void LocationBarViewMac::ShowFirstRunBubble() {
140 // We need the browser window to be shown before we can show the bubble, but 145 // We need the browser window to be shown before we can show the bubble, but
141 // we get called before that's happened. 146 // we get called before that's happened.
142 base::MessageLoop::current()->PostTask( 147 base::MessageLoop::current()->PostTask(
143 FROM_HERE, base::Bind(&LocationBarViewMac::ShowFirstRunBubbleInternal, 148 FROM_HERE, base::Bind(&LocationBarViewMac::ShowFirstRunBubbleInternal,
144 weak_ptr_factory_.GetWeakPtr())); 149 weak_ptr_factory_.GetWeakPtr()));
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 [cell addRightDecoration:page_action_decorations_[i]]; 403 [cell addRightDecoration:page_action_decorations_[i]];
399 } 404 }
400 405
401 for (ScopedVector<ContentSettingDecoration>::iterator i = 406 for (ScopedVector<ContentSettingDecoration>::iterator i =
402 content_setting_decorations_.begin(); 407 content_setting_decorations_.begin();
403 i != content_setting_decorations_.end(); ++i) { 408 i != content_setting_decorations_.end(); ++i) {
404 [cell addRightDecoration:*i]; 409 [cell addRightDecoration:*i];
405 } 410 }
406 411
407 [cell addRightDecoration:keyword_hint_decoration_.get()]; 412 [cell addRightDecoration:keyword_hint_decoration_.get()];
413 [cell addRightDecoration:mic_search_decoration_.get()];
408 414
409 // By default only the location icon is visible. 415 // By default only the location icon is visible.
410 location_icon_decoration_->SetVisible(true); 416 location_icon_decoration_->SetVisible(true);
411 selected_keyword_decoration_->SetVisible(false); 417 selected_keyword_decoration_->SetVisible(false);
412 ev_bubble_decoration_->SetVisible(false); 418 ev_bubble_decoration_->SetVisible(false);
413 keyword_hint_decoration_->SetVisible(false); 419 keyword_hint_decoration_->SetVisible(false);
414 420
415 // Get the keyword to use for keyword-search and hinting. 421 // Get the keyword to use for keyword-search and hinting.
416 const base::string16 keyword = omnibox_view_->model()->keyword(); 422 const base::string16 keyword = omnibox_view_->model()->keyword();
417 base::string16 short_name; 423 base::string16 short_name;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 omnibox_view_->ResetTabState(contents); 516 omnibox_view_->ResetTabState(contents);
511 } 517 }
512 518
513 void LocationBarViewMac::Update(const WebContents* contents) { 519 void LocationBarViewMac::Update(const WebContents* contents) {
514 UpdateManagePasswordsIconAndBubble(); 520 UpdateManagePasswordsIconAndBubble();
515 UpdateBookmarkStarVisibility(); 521 UpdateBookmarkStarVisibility();
516 UpdateTranslateDecoration(); 522 UpdateTranslateDecoration();
517 UpdateZoomDecoration(/*default_zoom_changed=*/false); 523 UpdateZoomDecoration(/*default_zoom_changed=*/false);
518 RefreshPageActionDecorations(); 524 RefreshPageActionDecorations();
519 RefreshContentSettingsDecorations(); 525 RefreshContentSettingsDecorations();
526 UpdateMicSearchDecorationVisibility();
520 if (contents) 527 if (contents)
521 omnibox_view_->OnTabChanged(contents); 528 omnibox_view_->OnTabChanged(contents);
522 else 529 else
523 omnibox_view_->Update(); 530 omnibox_view_->Update();
524 OnChanged(); 531 OnChanged();
525 } 532 }
526 533
527 void LocationBarViewMac::UpdateWithoutTabRestore() { 534 void LocationBarViewMac::UpdateWithoutTabRestore() {
528 Update(nullptr); 535 Update(nullptr);
529 } 536 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 profile())->GetTemplateURLForKeyword(keyword); 577 profile())->GetTemplateURLForKeyword(keyword);
571 if (template_url && 578 if (template_url &&
572 (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) { 579 (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) {
573 return extensions::OmniboxAPI::Get(profile())-> 580 return extensions::OmniboxAPI::Get(profile())->
574 GetOmniboxIcon(template_url->GetExtensionId()).AsNSImage(); 581 GetOmniboxIcon(template_url->GetExtensionId()).AsNSImage();
575 } 582 }
576 583
577 return OmniboxViewMac::ImageForResource(IDR_OMNIBOX_SEARCH); 584 return OmniboxViewMac::ImageForResource(IDR_OMNIBOX_SEARCH);
578 } 585 }
579 586
587 void LocationBarViewMac::ModelChanged(const SearchModel::State& old_state,
588 const SearchModel::State& new_state) {
589 if (UpdateMicSearchDecorationVisibility())
590 Layout();
591 }
592
580 void LocationBarViewMac::PostNotification(NSString* notification) { 593 void LocationBarViewMac::PostNotification(NSString* notification) {
581 [[NSNotificationCenter defaultCenter] postNotificationName:notification 594 [[NSNotificationCenter defaultCenter] postNotificationName:notification
582 object:[NSValue valueWithPointer:this]]; 595 object:[NSValue valueWithPointer:this]];
583 } 596 }
584 597
585 PageActionDecoration* LocationBarViewMac::GetPageActionDecoration( 598 PageActionDecoration* LocationBarViewMac::GetPageActionDecoration(
586 ExtensionAction* page_action) { 599 ExtensionAction* page_action) {
587 DCHECK(page_action); 600 DCHECK(page_action);
588 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { 601 for (size_t i = 0; i < page_action_decorations_.size(); ++i) {
589 if (page_action_decorations_[i]->GetPageAction() == page_action) 602 if (page_action_decorations_[i]->GetPageAction() == page_action)
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 720
708 return zoom_decoration_->UpdateIfNecessary( 721 return zoom_decoration_->UpdateIfNecessary(
709 ui_zoom::ZoomController::FromWebContents(web_contents), 722 ui_zoom::ZoomController::FromWebContents(web_contents),
710 default_zoom_changed); 723 default_zoom_changed);
711 } 724 }
712 725
713 void LocationBarViewMac::OnDefaultZoomLevelChanged() { 726 void LocationBarViewMac::OnDefaultZoomLevelChanged() {
714 if (UpdateZoomDecoration(/*default_zoom_changed=*/true)) 727 if (UpdateZoomDecoration(/*default_zoom_changed=*/true))
715 OnDecorationsChanged(); 728 OnDecorationsChanged();
716 } 729 }
730
731 bool LocationBarViewMac::UpdateMicSearchDecorationVisibility() {
732 bool is_visible = !GetToolbarModel()->input_in_progress() &&
733 browser_->search_model()->voice_search_supported();
734 if (mic_search_decoration_->IsVisible() == is_visible)
735 return false;
736 mic_search_decoration_->SetVisible(is_visible);
737 return true;
738 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698