| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 new SelectedKeywordDecoration(OmniboxViewMac::GetFieldFont())), | 85 new SelectedKeywordDecoration(OmniboxViewMac::GetFieldFont())), |
| 86 ev_bubble_decoration_( | 86 ev_bubble_decoration_( |
| 87 new EVBubbleDecoration(location_icon_decoration_.get(), | 87 new EVBubbleDecoration(location_icon_decoration_.get(), |
| 88 OmniboxViewMac::GetFieldFont())), | 88 OmniboxViewMac::GetFieldFont())), |
| 89 star_decoration_(new StarDecoration(command_updater)), | 89 star_decoration_(new StarDecoration(command_updater)), |
| 90 keyword_hint_decoration_( | 90 keyword_hint_decoration_( |
| 91 new KeywordHintDecoration(OmniboxViewMac::GetFieldFont())), | 91 new KeywordHintDecoration(OmniboxViewMac::GetFieldFont())), |
| 92 profile_(profile), | 92 profile_(profile), |
| 93 browser_(browser), | 93 browser_(browser), |
| 94 toolbar_model_(toolbar_model), | 94 toolbar_model_(toolbar_model), |
| 95 transition_(PageTransition::TYPED | PageTransition::FROM_ADDRESS_BAR), | 95 transition_(content::PageTransitionFromInt( |
| 96 content::PAGE_TRANSITION_TYPED | |
| 97 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)), |
| 96 weak_ptr_factory_(this) { | 98 weak_ptr_factory_(this) { |
| 97 for (size_t i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { | 99 for (size_t i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { |
| 98 DCHECK_EQ(i, content_setting_decorations_.size()); | 100 DCHECK_EQ(i, content_setting_decorations_.size()); |
| 99 ContentSettingsType type = static_cast<ContentSettingsType>(i); | 101 ContentSettingsType type = static_cast<ContentSettingsType>(i); |
| 100 content_setting_decorations_.push_back( | 102 content_setting_decorations_.push_back( |
| 101 new ContentSettingDecoration(type, this, profile_)); | 103 new ContentSettingDecoration(type, this, profile_)); |
| 102 } | 104 } |
| 103 | 105 |
| 104 registrar_.Add(this, | 106 registrar_.Add(this, |
| 105 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, | 107 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 | 147 |
| 146 void LocationBarViewMac::SetSuggestedText(const string16& text, | 148 void LocationBarViewMac::SetSuggestedText(const string16& text, |
| 147 InstantCompleteBehavior behavior) { | 149 InstantCompleteBehavior behavior) { |
| 148 omnibox_view_->model()->SetSuggestedText(text, behavior); | 150 omnibox_view_->model()->SetSuggestedText(text, behavior); |
| 149 } | 151 } |
| 150 | 152 |
| 151 WindowOpenDisposition LocationBarViewMac::GetWindowOpenDisposition() const { | 153 WindowOpenDisposition LocationBarViewMac::GetWindowOpenDisposition() const { |
| 152 return disposition_; | 154 return disposition_; |
| 153 } | 155 } |
| 154 | 156 |
| 155 PageTransition::Type LocationBarViewMac::GetPageTransition() const { | 157 content::PageTransition LocationBarViewMac::GetPageTransition() const { |
| 156 return transition_; | 158 return transition_; |
| 157 } | 159 } |
| 158 | 160 |
| 159 void LocationBarViewMac::AcceptInput() { | 161 void LocationBarViewMac::AcceptInput() { |
| 160 WindowOpenDisposition disposition = | 162 WindowOpenDisposition disposition = |
| 161 event_utils::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); | 163 event_utils::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); |
| 162 omnibox_view_->model()->AcceptInput(disposition, false); | 164 omnibox_view_->model()->AcceptInput(disposition, false); |
| 163 } | 165 } |
| 164 | 166 |
| 165 void LocationBarViewMac::FocusLocation(bool select_all) { | 167 void LocationBarViewMac::FocusLocation(bool select_all) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 bool star_enabled = IsStarEnabled(); | 213 bool star_enabled = IsStarEnabled(); |
| 212 command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled); | 214 command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled); |
| 213 star_decoration_->SetVisible(star_enabled); | 215 star_decoration_->SetVisible(star_enabled); |
| 214 RefreshPageActionDecorations(); | 216 RefreshPageActionDecorations(); |
| 215 RefreshContentSettingsDecorations(); | 217 RefreshContentSettingsDecorations(); |
| 216 // OmniboxView restores state if the tab is non-NULL. | 218 // OmniboxView restores state if the tab is non-NULL. |
| 217 omnibox_view_->Update(should_restore_state ? contents : NULL); | 219 omnibox_view_->Update(should_restore_state ? contents : NULL); |
| 218 OnChanged(); | 220 OnChanged(); |
| 219 } | 221 } |
| 220 | 222 |
| 221 void LocationBarViewMac::OnAutocompleteAccept(const GURL& url, | 223 void LocationBarViewMac::OnAutocompleteAccept( |
| 222 WindowOpenDisposition disposition, | 224 const GURL& url, |
| 223 PageTransition::Type transition, | 225 WindowOpenDisposition disposition, |
| 224 const GURL& alternate_nav_url) { | 226 content::PageTransition transition, |
| 227 const GURL& alternate_nav_url) { |
| 225 // WARNING: don't add an early return here. The calls after the if must | 228 // WARNING: don't add an early return here. The calls after the if must |
| 226 // happen. | 229 // happen. |
| 227 if (url.is_valid()) { | 230 if (url.is_valid()) { |
| 228 location_input_ = UTF8ToUTF16(url.spec()); | 231 location_input_ = UTF8ToUTF16(url.spec()); |
| 229 disposition_ = disposition; | 232 disposition_ = disposition; |
| 230 transition_ = transition | PageTransition::FROM_ADDRESS_BAR; | 233 transition_ = content::PageTransitionFromInt( |
| 234 transition | content::PAGE_TRANSITION_FROM_ADDRESS_BAR); |
| 231 | 235 |
| 232 if (command_updater_) { | 236 if (command_updater_) { |
| 233 if (!alternate_nav_url.is_valid()) { | 237 if (!alternate_nav_url.is_valid()) { |
| 234 command_updater_->ExecuteCommand(IDC_OPEN_CURRENT_URL); | 238 command_updater_->ExecuteCommand(IDC_OPEN_CURRENT_URL); |
| 235 } else { | 239 } else { |
| 236 AlternateNavURLFetcher* fetcher = | 240 AlternateNavURLFetcher* fetcher = |
| 237 new AlternateNavURLFetcher(alternate_nav_url); | 241 new AlternateNavURLFetcher(alternate_nav_url); |
| 238 // The AlternateNavURLFetcher will listen for the pending navigation | 242 // The AlternateNavURLFetcher will listen for the pending navigation |
| 239 // notification that will be issued as a result of the "open URL." It | 243 // notification that will be issued as a result of the "open URL." It |
| 240 // will automatically install itself into that navigation controller. | 244 // will automatically install itself into that navigation controller. |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 | 641 |
| 638 [field_ setNeedsDisplay:YES]; | 642 [field_ setNeedsDisplay:YES]; |
| 639 } | 643 } |
| 640 | 644 |
| 641 bool LocationBarViewMac::IsStarEnabled() { | 645 bool LocationBarViewMac::IsStarEnabled() { |
| 642 return [field_ isEditable] && | 646 return [field_ isEditable] && |
| 643 browser_defaults::bookmarks_enabled && | 647 browser_defaults::bookmarks_enabled && |
| 644 !toolbar_model_->input_in_progress() && | 648 !toolbar_model_->input_in_progress() && |
| 645 edit_bookmarks_enabled_.GetValue(); | 649 edit_bookmarks_enabled_.GetValue(); |
| 646 } | 650 } |
| OLD | NEW |