OLD | NEW |
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.h" | 9 #include "base/message_loop.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h" | 37 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h" |
38 #import "chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.h" | 38 #import "chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.h" |
39 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h" | 39 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h" |
40 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h" | 40 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h" |
41 #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h" | 41 #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h" |
42 #import "chrome/browser/ui/cocoa/location_bar/plus_decoration.h" | 42 #import "chrome/browser/ui/cocoa/location_bar/plus_decoration.h" |
43 #import "chrome/browser/ui/cocoa/location_bar/search_token_decoration.h" | 43 #import "chrome/browser/ui/cocoa/location_bar/search_token_decoration.h" |
44 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" | 44 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" |
45 #import "chrome/browser/ui/cocoa/location_bar/separator_decoration.h" | 45 #import "chrome/browser/ui/cocoa/location_bar/separator_decoration.h" |
46 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" | 46 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" |
47 #import "chrome/browser/ui/cocoa/location_bar/web_intents_button_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 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | 49 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
51 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" | 50 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" |
52 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" | |
53 #include "chrome/browser/ui/omnibox/alternate_nav_url_fetcher.h" | 51 #include "chrome/browser/ui/omnibox/alternate_nav_url_fetcher.h" |
54 #include "chrome/browser/ui/omnibox/location_bar_util.h" | 52 #include "chrome/browser/ui/omnibox/location_bar_util.h" |
55 #import "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 53 #import "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
56 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 54 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
57 #include "chrome/browser/ui/zoom/zoom_controller.h" | 55 #include "chrome/browser/ui/zoom/zoom_controller.h" |
58 #include "chrome/common/chrome_notification_types.h" | 56 #include "chrome/common/chrome_notification_types.h" |
59 #include "chrome/common/chrome_switches.h" | 57 #include "chrome/common/chrome_switches.h" |
60 #include "chrome/common/extensions/extension.h" | 58 #include "chrome/common/extensions/extension.h" |
61 #include "chrome/common/extensions/extension_resource.h" | 59 #include "chrome/common/extensions/extension_resource.h" |
62 #include "chrome/common/extensions/feature_switch.h" | 60 #include "chrome/common/extensions/feature_switch.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 new SelectedKeywordDecoration(OmniboxViewMac::GetFieldFont())), | 99 new SelectedKeywordDecoration(OmniboxViewMac::GetFieldFont())), |
102 separator_decoration_(new SeparatorDecoration()), | 100 separator_decoration_(new SeparatorDecoration()), |
103 ev_bubble_decoration_( | 101 ev_bubble_decoration_( |
104 new EVBubbleDecoration(location_icon_decoration_.get(), | 102 new EVBubbleDecoration(location_icon_decoration_.get(), |
105 OmniboxViewMac::GetFieldFont())), | 103 OmniboxViewMac::GetFieldFont())), |
106 plus_decoration_(NULL), | 104 plus_decoration_(NULL), |
107 star_decoration_(new StarDecoration(command_updater)), | 105 star_decoration_(new StarDecoration(command_updater)), |
108 zoom_decoration_(new ZoomDecoration(toolbar_model)), | 106 zoom_decoration_(new ZoomDecoration(toolbar_model)), |
109 keyword_hint_decoration_( | 107 keyword_hint_decoration_( |
110 new KeywordHintDecoration(OmniboxViewMac::GetFieldFont())), | 108 new KeywordHintDecoration(OmniboxViewMac::GetFieldFont())), |
111 #if defined(ENABLE_WEB_INTENTS) | |
112 web_intents_button_decoration_( | |
113 new WebIntentsButtonDecoration(this, OmniboxViewMac::GetFieldFont())), | |
114 #endif | |
115 profile_(profile), | 109 profile_(profile), |
116 browser_(browser), | 110 browser_(browser), |
117 toolbar_model_(toolbar_model), | 111 toolbar_model_(toolbar_model), |
118 transition_(content::PageTransitionFromInt( | 112 transition_(content::PageTransitionFromInt( |
119 content::PAGE_TRANSITION_TYPED | | 113 content::PAGE_TRANSITION_TYPED | |
120 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)), | 114 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)), |
121 weak_ptr_factory_(this) { | 115 weak_ptr_factory_(this) { |
122 if (extensions::FeatureSwitch::action_box()->IsEnabled()) { | 116 if (extensions::FeatureSwitch::action_box()->IsEnabled()) { |
123 plus_decoration_.reset(new PlusDecoration(this, browser_)); | 117 plus_decoration_.reset(new PlusDecoration(this, browser_)); |
124 } | 118 } |
125 | 119 |
126 for (size_t i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { | 120 for (size_t i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { |
127 DCHECK_EQ(i, content_setting_decorations_.size()); | 121 DCHECK_EQ(i, content_setting_decorations_.size()); |
128 ContentSettingsType type = static_cast<ContentSettingsType>(i); | 122 ContentSettingsType type = static_cast<ContentSettingsType>(i); |
129 content_setting_decorations_.push_back( | 123 content_setting_decorations_.push_back( |
130 new ContentSettingDecoration(type, this, profile_)); | 124 new ContentSettingDecoration(type, this, profile_)); |
131 } | 125 } |
132 | 126 |
133 #if defined(ENABLE_WEB_INTENTS) | |
134 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
135 web_intents_button_decoration_->SetButtonImages( | |
136 rb.GetNativeImageNamed(IDR_OMNIBOX_WI_BUBBLE_BACKGROUND_L).ToNSImage(), | |
137 rb.GetNativeImageNamed(IDR_OMNIBOX_WI_BUBBLE_BACKGROUND_C).ToNSImage(), | |
138 rb.GetNativeImageNamed(IDR_OMNIBOX_WI_BUBBLE_BACKGROUND_R).ToNSImage()); | |
139 #endif | |
140 | |
141 registrar_.Add(this, | 127 registrar_.Add(this, |
142 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, | 128 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, |
143 content::NotificationService::AllSources()); | 129 content::NotificationService::AllSources()); |
144 registrar_.Add(this, | 130 registrar_.Add(this, |
145 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, | 131 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, |
146 content::Source<Profile>(browser_->profile())); | 132 content::Source<Profile>(browser_->profile())); |
147 | 133 |
148 edit_bookmarks_enabled_.Init( | 134 edit_bookmarks_enabled_.Init( |
149 prefs::kEditBookmarksEnabled, | 135 prefs::kEditBookmarksEnabled, |
150 profile_->GetPrefs(), | 136 profile_->GetPrefs(), |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 DeletePageActionDecorations(); | 225 DeletePageActionDecorations(); |
240 Layout(); | 226 Layout(); |
241 if (page_action_decorations_.size() != count_before) { | 227 if (page_action_decorations_.size() != count_before) { |
242 content::NotificationService::current()->Notify( | 228 content::NotificationService::current()->Notify( |
243 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, | 229 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, |
244 content::Source<LocationBar>(this), | 230 content::Source<LocationBar>(this), |
245 content::NotificationService::NoDetails()); | 231 content::NotificationService::NoDetails()); |
246 } | 232 } |
247 } | 233 } |
248 | 234 |
249 #if defined(ENABLE_WEB_INTENTS) | |
250 void LocationBarViewMac::UpdateWebIntentsButton() { | |
251 RefreshWebIntentsButtonDecoration(); | |
252 } | |
253 #endif | |
254 | |
255 void LocationBarViewMac::UpdateOpenPDFInReaderPrompt() { | 235 void LocationBarViewMac::UpdateOpenPDFInReaderPrompt() { |
256 // Not implemented on Mac. | 236 // Not implemented on Mac. |
257 } | 237 } |
258 | 238 |
259 void LocationBarViewMac::SaveStateToContents(WebContents* contents) { | 239 void LocationBarViewMac::SaveStateToContents(WebContents* contents) { |
260 // TODO(shess): Why SaveStateToContents vs SaveStateToTab? | 240 // TODO(shess): Why SaveStateToContents vs SaveStateToTab? |
261 omnibox_view_->SaveStateToTab(contents); | 241 omnibox_view_->SaveStateToTab(contents); |
262 } | 242 } |
263 | 243 |
264 void LocationBarViewMac::Update(const WebContents* contents, | 244 void LocationBarViewMac::Update(const WebContents* contents, |
265 bool should_restore_state) { | 245 bool should_restore_state) { |
266 command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, IsStarEnabled()); | 246 command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, IsStarEnabled()); |
267 UpdateStarDecorationVisibility(); | 247 UpdateStarDecorationVisibility(); |
268 UpdatePlusDecorationVisibility(); | 248 UpdatePlusDecorationVisibility(); |
269 UpdateZoomDecoration(); | 249 UpdateZoomDecoration(); |
270 RefreshPageActionDecorations(); | 250 RefreshPageActionDecorations(); |
271 RefreshContentSettingsDecorations(); | 251 RefreshContentSettingsDecorations(); |
272 RefreshWebIntentsButtonDecoration(); | |
273 // OmniboxView restores state if the tab is non-NULL. | 252 // OmniboxView restores state if the tab is non-NULL. |
274 omnibox_view_->Update(should_restore_state ? contents : NULL); | 253 omnibox_view_->Update(should_restore_state ? contents : NULL); |
275 OnChanged(); | 254 OnChanged(); |
276 } | 255 } |
277 | 256 |
278 void LocationBarViewMac::OnAutocompleteAccept( | 257 void LocationBarViewMac::OnAutocompleteAccept( |
279 const GURL& url, | 258 const GURL& url, |
280 WindowOpenDisposition disposition, | 259 WindowOpenDisposition disposition, |
281 content::PageTransition transition, | 260 content::PageTransition transition, |
282 const GURL& alternate_nav_url) { | 261 const GURL& alternate_nav_url) { |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 } | 644 } |
666 | 645 |
667 GURL url = toolbar_model_->GetURL(); | 646 GURL url = toolbar_model_->GetURL(); |
668 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { | 647 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { |
669 page_action_decorations_[i]->UpdateVisibility( | 648 page_action_decorations_[i]->UpdateVisibility( |
670 toolbar_model_->GetInputInProgress() ? NULL : web_contents, | 649 toolbar_model_->GetInputInProgress() ? NULL : web_contents, |
671 url); | 650 url); |
672 } | 651 } |
673 } | 652 } |
674 | 653 |
675 void LocationBarViewMac::RefreshWebIntentsButtonDecoration() { | |
676 #if defined(ENABLE_WEB_INTENTS) | |
677 WebContents* web_contents = GetWebContents(); | |
678 if (!web_contents) { | |
679 web_intents_button_decoration_->SetVisible(false); | |
680 return; | |
681 } | |
682 | |
683 web_intents_button_decoration_->Update(web_contents); | |
684 #endif | |
685 } | |
686 | |
687 // TODO(shess): This function should over time grow to closely match | 654 // TODO(shess): This function should over time grow to closely match |
688 // the views Layout() function. | 655 // the views Layout() function. |
689 void LocationBarViewMac::Layout() { | 656 void LocationBarViewMac::Layout() { |
690 AutocompleteTextFieldCell* cell = [field_ cell]; | 657 AutocompleteTextFieldCell* cell = [field_ cell]; |
691 | 658 |
692 // Reset the left-hand decorations. | 659 // Reset the left-hand decorations. |
693 // TODO(shess): Shortly, this code will live somewhere else, like in | 660 // TODO(shess): Shortly, this code will live somewhere else, like in |
694 // the constructor. I am still wrestling with how best to deal with | 661 // the constructor. I am still wrestling with how best to deal with |
695 // right-hand decorations, which are not a static set. | 662 // right-hand decorations, which are not a static set. |
696 [cell clearDecorations]; | 663 [cell clearDecorations]; |
697 [cell addLeftDecoration:location_icon_decoration_.get()]; | 664 [cell addLeftDecoration:location_icon_decoration_.get()]; |
698 [cell addLeftDecoration:selected_keyword_decoration_.get()]; | 665 [cell addLeftDecoration:selected_keyword_decoration_.get()]; |
699 [cell addLeftDecoration:ev_bubble_decoration_.get()]; | 666 [cell addLeftDecoration:ev_bubble_decoration_.get()]; |
700 if (plus_decoration_.get()) | 667 if (plus_decoration_.get()) |
701 [cell addRightDecoration:plus_decoration_.get()]; | 668 [cell addRightDecoration:plus_decoration_.get()]; |
702 [cell addRightDecoration:star_decoration_.get()]; | 669 [cell addRightDecoration:star_decoration_.get()]; |
703 // TODO(dbeam): uncomment when zoom bubble exists. | 670 // TODO(dbeam): uncomment when zoom bubble exists. |
704 // [cell addRightDecoration:zoom_decoration_.get()]; | 671 // [cell addRightDecoration:zoom_decoration_.get()]; |
705 | 672 |
706 // Note that display order is right to left. | 673 // Note that display order is right to left. |
707 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { | 674 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { |
708 [cell addRightDecoration:page_action_decorations_[i]]; | 675 [cell addRightDecoration:page_action_decorations_[i]]; |
709 } | 676 } |
710 for (size_t i = 0; i < content_setting_decorations_.size(); ++i) { | 677 for (size_t i = 0; i < content_setting_decorations_.size(); ++i) { |
711 [cell addRightDecoration:content_setting_decorations_[i]]; | 678 [cell addRightDecoration:content_setting_decorations_[i]]; |
712 } | 679 } |
713 | 680 |
714 [cell addRightDecoration:keyword_hint_decoration_.get()]; | 681 [cell addRightDecoration:keyword_hint_decoration_.get()]; |
715 | 682 |
716 #if defined(ENABLE_WEB_INTENTS) | |
717 [cell addRightDecoration:web_intents_button_decoration_.get()]; | |
718 #endif | |
719 | |
720 [cell addRightDecoration:separator_decoration_.get()]; | 683 [cell addRightDecoration:separator_decoration_.get()]; |
721 [cell addRightDecoration:search_token_decoration_.get()]; | 684 [cell addRightDecoration:search_token_decoration_.get()]; |
722 | 685 |
723 // By default only the location icon is visible. | 686 // By default only the location icon is visible. |
724 location_icon_decoration_->SetVisible(true); | 687 location_icon_decoration_->SetVisible(true); |
725 selected_keyword_decoration_->SetVisible(false); | 688 selected_keyword_decoration_->SetVisible(false); |
726 ev_bubble_decoration_->SetVisible(false); | 689 ev_bubble_decoration_->SetVisible(false); |
727 keyword_hint_decoration_->SetVisible(false); | 690 keyword_hint_decoration_->SetVisible(false); |
728 separator_decoration_->SetVisible(false); | 691 separator_decoration_->SetVisible(false); |
729 search_token_decoration_->SetVisible(false); | 692 search_token_decoration_->SetVisible(false); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 if (!toolbar_model_->GetInputInProgress() && | 783 if (!toolbar_model_->GetInputInProgress() && |
821 toolbar_model_->WouldReplaceSearchURLWithSearchTerms()) { | 784 toolbar_model_->WouldReplaceSearchURLWithSearchTerms()) { |
822 const TemplateURL* template_url = | 785 const TemplateURL* template_url = |
823 TemplateURLServiceFactory::GetForProfile(profile_)-> | 786 TemplateURLServiceFactory::GetForProfile(profile_)-> |
824 GetDefaultSearchProvider(); | 787 GetDefaultSearchProvider(); |
825 if (template_url) | 788 if (template_url) |
826 return template_url->short_name(); | 789 return template_url->short_name(); |
827 } | 790 } |
828 return string16(); | 791 return string16(); |
829 } | 792 } |
OLD | NEW |