OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/cocoa/location_bar/location_bar_view_mac.h" | 5 #import "chrome/browser/cocoa/location_bar/location_bar_view_mac.h" |
6 | 6 |
7 #include "app/l10n_util_mac.h" | 7 #include "app/l10n_util_mac.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/nsimage_cache_mac.h" | 10 #include "base/nsimage_cache_mac.h" |
11 #include "base/stl_util-inl.h" | 11 #include "base/stl_util-inl.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/sys_string_conversions.h" | 13 #include "base/sys_string_conversions.h" |
14 #include "chrome/app/chrome_dll_resource.h" | 14 #include "chrome/app/chrome_dll_resource.h" |
15 #include "chrome/browser/alternate_nav_url_fetcher.h" | 15 #include "chrome/browser/alternate_nav_url_fetcher.h" |
16 #import "chrome/browser/app_controller_mac.h" | 16 #import "chrome/browser/app_controller_mac.h" |
17 #import "chrome/browser/autocomplete/autocomplete_edit_view_mac.h" | 17 #import "chrome/browser/autocomplete/autocomplete_edit_view_mac.h" |
18 #include "chrome/browser/browser_list.h" | 18 #include "chrome/browser/browser_list.h" |
19 #import "chrome/browser/cocoa/content_blocked_bubble_controller.h" | 19 #import "chrome/browser/cocoa/content_blocked_bubble_controller.h" |
20 #include "chrome/browser/cocoa/event_utils.h" | 20 #include "chrome/browser/cocoa/event_utils.h" |
21 #import "chrome/browser/cocoa/extensions/extension_action_context_menu.h" | 21 #import "chrome/browser/cocoa/extensions/extension_action_context_menu.h" |
22 #import "chrome/browser/cocoa/extensions/extension_popup_controller.h" | 22 #import "chrome/browser/cocoa/extensions/extension_popup_controller.h" |
| 23 #import "chrome/browser/cocoa/first_run_bubble_controller.h" |
23 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field.h" | 24 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field.h" |
24 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.h" | 25 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.h" |
25 #include "chrome/browser/command_updater.h" | 26 #include "chrome/browser/command_updater.h" |
26 #include "chrome/browser/content_setting_image_model.h" | 27 #include "chrome/browser/content_setting_image_model.h" |
27 #include "chrome/browser/content_setting_bubble_model.h" | 28 #include "chrome/browser/content_setting_bubble_model.h" |
28 #include "chrome/browser/extensions/extension_browser_event_router.h" | 29 #include "chrome/browser/extensions/extension_browser_event_router.h" |
29 #include "chrome/browser/extensions/extensions_service.h" | 30 #include "chrome/browser/extensions/extensions_service.h" |
30 #include "chrome/browser/extensions/extension_tabs_module.h" | 31 #include "chrome/browser/extensions/extension_tabs_module.h" |
31 #include "chrome/browser/location_bar_util.h" | 32 #include "chrome/browser/location_bar_util.h" |
32 #include "chrome/browser/profile.h" | 33 #include "chrome/browser/profile.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 command_updater_(command_updater), | 73 command_updater_(command_updater), |
73 field_(field), | 74 field_(field), |
74 disposition_(CURRENT_TAB), | 75 disposition_(CURRENT_TAB), |
75 location_icon_view_(this), | 76 location_icon_view_(this), |
76 security_label_view_(), | 77 security_label_view_(), |
77 star_icon_view_(command_updater), | 78 star_icon_view_(command_updater), |
78 page_action_views_(this, profile, toolbar_model), | 79 page_action_views_(this, profile, toolbar_model), |
79 profile_(profile), | 80 profile_(profile), |
80 browser_(browser), | 81 browser_(browser), |
81 toolbar_model_(toolbar_model), | 82 toolbar_model_(toolbar_model), |
82 transition_(PageTransition::TYPED) { | 83 transition_(PageTransition::TYPED), |
| 84 first_run_bubble_(this) { |
83 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { | 85 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { |
84 ContentSettingImageView* content_setting_view = | 86 ContentSettingImageView* content_setting_view = |
85 new ContentSettingImageView(static_cast<ContentSettingsType>(i), this, | 87 new ContentSettingImageView(static_cast<ContentSettingsType>(i), this, |
86 profile_); | 88 profile_); |
87 content_setting_views_.push_back(content_setting_view); | 89 content_setting_views_.push_back(content_setting_view); |
88 content_setting_view->SetVisible(false); | 90 content_setting_view->SetVisible(false); |
89 } | 91 } |
90 | 92 |
91 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; | 93 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; |
92 [cell setLocationIconView:&location_icon_view_]; | 94 [cell setLocationIconView:&location_icon_view_]; |
93 [cell setSecurityLabelView:&security_label_view_]; | 95 [cell setSecurityLabelView:&security_label_view_]; |
94 [cell setStarIconView:&star_icon_view_]; | 96 [cell setStarIconView:&star_icon_view_]; |
95 [cell setPageActionViewList:&page_action_views_]; | 97 [cell setPageActionViewList:&page_action_views_]; |
96 [cell setContentSettingViewsList:&content_setting_views_]; | 98 [cell setContentSettingViewsList:&content_setting_views_]; |
97 | 99 |
98 registrar_.Add(this, | 100 registrar_.Add(this, |
99 NotificationType::EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, | 101 NotificationType::EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, |
100 NotificationService::AllSources()); | 102 NotificationService::AllSources()); |
101 } | 103 } |
102 | 104 |
103 LocationBarViewMac::~LocationBarViewMac() { | 105 LocationBarViewMac::~LocationBarViewMac() { |
104 // Disconnect from cell in case it outlives us. | 106 // Disconnect from cell in case it outlives us. |
105 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; | 107 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; |
106 [cell setPageActionViewList:NULL]; | 108 [cell setPageActionViewList:NULL]; |
107 [cell setLocationIconView:NULL]; | 109 [cell setLocationIconView:NULL]; |
108 [cell setSecurityLabelView:NULL]; | 110 [cell setSecurityLabelView:NULL]; |
109 [cell setStarIconView:NULL]; | 111 [cell setStarIconView:NULL]; |
110 } | 112 } |
111 | 113 |
| 114 void LocationBarViewMac::ShowFirstRunBubble(FirstRun::BubbleType bubble_type) { |
| 115 // We need the browser window to be shown before we can show the bubble, but |
| 116 // we get called before that's happened. |
| 117 Task* task = first_run_bubble_.NewRunnableMethod( |
| 118 &LocationBarViewMac::ShowFirstRunBubbleInternal, bubble_type); |
| 119 MessageLoop::current()->PostTask(FROM_HERE, task); |
| 120 } |
| 121 |
| 122 void LocationBarViewMac::ShowFirstRunBubbleInternal( |
| 123 FirstRun::BubbleType bubble_type) { |
| 124 if (!field_ || ![field_ window]) |
| 125 return; |
| 126 |
| 127 // The bubble needs to be just below the Omnibox and slightly to the right |
| 128 // of the left omnibox icon, so shift x and y co-ordinates. |
| 129 const NSPoint kOffset = NSMakePoint(-18, 4); |
| 130 [FirstRunBubbleController showForView:field_ offset:kOffset profile:profile_]; |
| 131 } |
| 132 |
112 std::wstring LocationBarViewMac::GetInputString() const { | 133 std::wstring LocationBarViewMac::GetInputString() const { |
113 return location_input_; | 134 return location_input_; |
114 } | 135 } |
115 | 136 |
116 WindowOpenDisposition LocationBarViewMac::GetWindowOpenDisposition() const { | 137 WindowOpenDisposition LocationBarViewMac::GetWindowOpenDisposition() const { |
117 return disposition_; | 138 return disposition_; |
118 } | 139 } |
119 | 140 |
120 PageTransition::Type LocationBarViewMac::GetPageTransition() const { | 141 PageTransition::Type LocationBarViewMac::GetPageTransition() const { |
121 return transition_; | 142 return transition_; |
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 NSWindow* window = [textField window]; | 902 NSWindow* window = [textField window]; |
882 bounds = [textField convertRect:bounds toView:nil]; | 903 bounds = [textField convertRect:bounds toView:nil]; |
883 NSPoint anchor = NSMakePoint(NSMidX(bounds) + 1, NSMinY(bounds)); | 904 NSPoint anchor = NSMakePoint(NSMidX(bounds) + 1, NSMinY(bounds)); |
884 anchor = [window convertBaseToScreen:anchor]; | 905 anchor = [window convertBaseToScreen:anchor]; |
885 | 906 |
886 // Open bubble. | 907 // Open bubble. |
887 ContentSettingBubbleModel* model = | 908 ContentSettingBubbleModel* model = |
888 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 909 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
889 tabContents, profile_, | 910 tabContents, profile_, |
890 content_setting_image_model_->get_content_settings_type()); | 911 content_setting_image_model_->get_content_settings_type()); |
891 [[ContentBlockedBubbleController showForModel:model | 912 [ContentBlockedBubbleController showForModel:model |
892 parentWindow:window | 913 parentWindow:window |
893 anchoredAt:anchor] showWindow:nil]; | 914 anchoredAt:anchor]; |
894 } | 915 } |
895 | 916 |
896 NSString* LocationBarViewMac::ContentSettingImageView::GetToolTip() { | 917 NSString* LocationBarViewMac::ContentSettingImageView::GetToolTip() { |
897 return tooltip_.get(); | 918 return tooltip_.get(); |
898 } | 919 } |
899 | 920 |
900 void LocationBarViewMac::ContentSettingImageView::UpdateFromTabContents( | 921 void LocationBarViewMac::ContentSettingImageView::UpdateFromTabContents( |
901 const TabContents* tab_contents) { | 922 const TabContents* tab_contents) { |
902 content_setting_image_model_->UpdateFromTabContents(tab_contents); | 923 content_setting_image_model_->UpdateFromTabContents(tab_contents); |
903 if (content_setting_image_model_->is_visible()) { | 924 if (content_setting_image_model_->is_visible()) { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
984 ++result; | 1005 ++result; |
985 } | 1006 } |
986 return result; | 1007 return result; |
987 } | 1008 } |
988 | 1009 |
989 void LocationBarViewMac::PageActionViewList::OnMousePressed(NSRect iconFrame, | 1010 void LocationBarViewMac::PageActionViewList::OnMousePressed(NSRect iconFrame, |
990 size_t index) { | 1011 size_t index) { |
991 ViewAt(index)->OnMousePressed(iconFrame); | 1012 ViewAt(index)->OnMousePressed(iconFrame); |
992 } | 1013 } |
993 | 1014 |
OLD | NEW |