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

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

Issue 1428423002: Remove setVoiceSearchSupported part of EmbeddedSearch SearchBox API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mac fix 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 for (ContentSettingsType type : 109 for (ContentSettingsType type :
112 ContentSettingBubbleModel::GetSupportedBubbleTypes()) { 110 ContentSettingBubbleModel::GetSupportedBubbleTypes()) {
113 content_setting_decorations_.push_back( 111 content_setting_decorations_.push_back(
114 new ContentSettingDecoration(type, this, profile)); 112 new ContentSettingDecoration(type, this, profile));
115 } 113 }
116 114
117 edit_bookmarks_enabled_.Init( 115 edit_bookmarks_enabled_.Init(
118 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(), 116 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(),
119 base::Bind(&LocationBarViewMac::OnEditBookmarksEnabledChanged, 117 base::Bind(&LocationBarViewMac::OnEditBookmarksEnabledChanged,
120 base::Unretained(this))); 118 base::Unretained(this)));
121 119
122 browser_->search_model()->AddObserver(this);
123
124 ui_zoom::ZoomEventManager::GetForBrowserContext(profile) 120 ui_zoom::ZoomEventManager::GetForBrowserContext(profile)
125 ->AddZoomEventManagerObserver(this); 121 ->AddZoomEventManagerObserver(this);
126 122
127 [[field_ cell] setIsPopupMode: 123 [[field_ cell] setIsPopupMode:
128 !browser->SupportsWindowFeature(Browser::FEATURE_TABSTRIP)]; 124 !browser->SupportsWindowFeature(Browser::FEATURE_TABSTRIP)];
129 125
130 // Sets images for the decorations, and performs a layout. This call ensures 126 // Sets images for the decorations, and performs a layout. This call ensures
131 // that this class is in a consistent state after initialization. 127 // that this class is in a consistent state after initialization.
132 OnChanged(); 128 OnChanged();
133 } 129 }
134 130
135 LocationBarViewMac::~LocationBarViewMac() { 131 LocationBarViewMac::~LocationBarViewMac() {
136 // Disconnect from cell in case it outlives us. 132 // Disconnect from cell in case it outlives us.
137 [[field_ cell] clearDecorations]; 133 [[field_ cell] clearDecorations];
138 134
139 browser_->search_model()->RemoveObserver(this);
140 ui_zoom::ZoomEventManager::GetForBrowserContext(profile()) 135 ui_zoom::ZoomEventManager::GetForBrowserContext(profile())
141 ->RemoveZoomEventManagerObserver(this); 136 ->RemoveZoomEventManagerObserver(this);
142 } 137 }
143 138
144 void LocationBarViewMac::ShowFirstRunBubble() { 139 void LocationBarViewMac::ShowFirstRunBubble() {
145 // We need the browser window to be shown before we can show the bubble, but 140 // We need the browser window to be shown before we can show the bubble, but
146 // we get called before that's happened. 141 // we get called before that's happened.
147 base::MessageLoop::current()->PostTask( 142 base::MessageLoop::current()->PostTask(
148 FROM_HERE, base::Bind(&LocationBarViewMac::ShowFirstRunBubbleInternal, 143 FROM_HERE, base::Bind(&LocationBarViewMac::ShowFirstRunBubbleInternal,
149 weak_ptr_factory_.GetWeakPtr())); 144 weak_ptr_factory_.GetWeakPtr()));
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 [cell addRightDecoration:page_action_decorations_[i]]; 398 [cell addRightDecoration:page_action_decorations_[i]];
404 } 399 }
405 400
406 for (ScopedVector<ContentSettingDecoration>::iterator i = 401 for (ScopedVector<ContentSettingDecoration>::iterator i =
407 content_setting_decorations_.begin(); 402 content_setting_decorations_.begin();
408 i != content_setting_decorations_.end(); ++i) { 403 i != content_setting_decorations_.end(); ++i) {
409 [cell addRightDecoration:*i]; 404 [cell addRightDecoration:*i];
410 } 405 }
411 406
412 [cell addRightDecoration:keyword_hint_decoration_.get()]; 407 [cell addRightDecoration:keyword_hint_decoration_.get()];
413 [cell addRightDecoration:mic_search_decoration_.get()];
414 408
415 // By default only the location icon is visible. 409 // By default only the location icon is visible.
416 location_icon_decoration_->SetVisible(true); 410 location_icon_decoration_->SetVisible(true);
417 selected_keyword_decoration_->SetVisible(false); 411 selected_keyword_decoration_->SetVisible(false);
418 ev_bubble_decoration_->SetVisible(false); 412 ev_bubble_decoration_->SetVisible(false);
419 keyword_hint_decoration_->SetVisible(false); 413 keyword_hint_decoration_->SetVisible(false);
420 414
421 // Get the keyword to use for keyword-search and hinting. 415 // Get the keyword to use for keyword-search and hinting.
422 const base::string16 keyword = omnibox_view_->model()->keyword(); 416 const base::string16 keyword = omnibox_view_->model()->keyword();
423 base::string16 short_name; 417 base::string16 short_name;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 omnibox_view_->ResetTabState(contents); 510 omnibox_view_->ResetTabState(contents);
517 } 511 }
518 512
519 void LocationBarViewMac::Update(const WebContents* contents) { 513 void LocationBarViewMac::Update(const WebContents* contents) {
520 UpdateManagePasswordsIconAndBubble(); 514 UpdateManagePasswordsIconAndBubble();
521 UpdateBookmarkStarVisibility(); 515 UpdateBookmarkStarVisibility();
522 UpdateTranslateDecoration(); 516 UpdateTranslateDecoration();
523 UpdateZoomDecoration(/*default_zoom_changed=*/false); 517 UpdateZoomDecoration(/*default_zoom_changed=*/false);
524 RefreshPageActionDecorations(); 518 RefreshPageActionDecorations();
525 RefreshContentSettingsDecorations(); 519 RefreshContentSettingsDecorations();
526 UpdateMicSearchDecorationVisibility();
527 if (contents) 520 if (contents)
528 omnibox_view_->OnTabChanged(contents); 521 omnibox_view_->OnTabChanged(contents);
529 else 522 else
530 omnibox_view_->Update(); 523 omnibox_view_->Update();
531 OnChanged(); 524 OnChanged();
532 } 525 }
533 526
534 void LocationBarViewMac::UpdateWithoutTabRestore() { 527 void LocationBarViewMac::UpdateWithoutTabRestore() {
535 Update(nullptr); 528 Update(nullptr);
536 } 529 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 profile())->GetTemplateURLForKeyword(keyword); 570 profile())->GetTemplateURLForKeyword(keyword);
578 if (template_url && 571 if (template_url &&
579 (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) { 572 (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION)) {
580 return extensions::OmniboxAPI::Get(profile())-> 573 return extensions::OmniboxAPI::Get(profile())->
581 GetOmniboxIcon(template_url->GetExtensionId()).AsNSImage(); 574 GetOmniboxIcon(template_url->GetExtensionId()).AsNSImage();
582 } 575 }
583 576
584 return OmniboxViewMac::ImageForResource(IDR_OMNIBOX_SEARCH); 577 return OmniboxViewMac::ImageForResource(IDR_OMNIBOX_SEARCH);
585 } 578 }
586 579
587 void LocationBarViewMac::ModelChanged(const SearchModel::State& old_state,
588 const SearchModel::State& new_state) {
589 if (UpdateMicSearchDecorationVisibility())
590 Layout();
591 }
592
593 void LocationBarViewMac::PostNotification(NSString* notification) { 580 void LocationBarViewMac::PostNotification(NSString* notification) {
594 [[NSNotificationCenter defaultCenter] postNotificationName:notification 581 [[NSNotificationCenter defaultCenter] postNotificationName:notification
595 object:[NSValue valueWithPointer:this]]; 582 object:[NSValue valueWithPointer:this]];
596 } 583 }
597 584
598 PageActionDecoration* LocationBarViewMac::GetPageActionDecoration( 585 PageActionDecoration* LocationBarViewMac::GetPageActionDecoration(
599 ExtensionAction* page_action) { 586 ExtensionAction* page_action) {
600 DCHECK(page_action); 587 DCHECK(page_action);
601 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { 588 for (size_t i = 0; i < page_action_decorations_.size(); ++i) {
602 if (page_action_decorations_[i]->GetPageAction() == page_action) 589 if (page_action_decorations_[i]->GetPageAction() == page_action)
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 707
721 return zoom_decoration_->UpdateIfNecessary( 708 return zoom_decoration_->UpdateIfNecessary(
722 ui_zoom::ZoomController::FromWebContents(web_contents), 709 ui_zoom::ZoomController::FromWebContents(web_contents),
723 default_zoom_changed); 710 default_zoom_changed);
724 } 711 }
725 712
726 void LocationBarViewMac::OnDefaultZoomLevelChanged() { 713 void LocationBarViewMac::OnDefaultZoomLevelChanged() {
727 if (UpdateZoomDecoration(/*default_zoom_changed=*/true)) 714 if (UpdateZoomDecoration(/*default_zoom_changed=*/true))
728 OnDecorationsChanged(); 715 OnDecorationsChanged();
729 } 716 }
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