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

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

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

Powered by Google App Engine
This is Rietveld 408576698