| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import "chrome/browser/cocoa/location_bar_view_mac.h" | |
| 6 | |
| 7 #include "base/string_util.h" | |
| 8 #include "chrome/app/chrome_dll_resource.h" | |
| 9 #include "chrome/browser/alternate_nav_url_fetcher.h" | |
| 10 #import "chrome/browser/app_controller_mac.h" | |
| 11 #import "chrome/browser/autocomplete/autocomplete_edit_view_mac.h" | |
| 12 #include "chrome/browser/command_updater.h" | |
| 13 #include "skia/include/SkBitmap.h" | |
| 14 | |
| 15 // TODO(shess): This code is mostly copied from the gtk | |
| 16 // implementation. Make sure it's all appropriate and flesh it out. | |
| 17 | |
| 18 LocationBarViewMac::LocationBarViewMac(CommandUpdater* command_updater, | |
| 19 ToolbarModel* toolbar_model) | |
| 20 : command_updater_(command_updater), | |
| 21 toolbar_model_(toolbar_model), | |
| 22 disposition_(CURRENT_TAB), | |
| 23 transition_(PageTransition::TYPED) { | |
| 24 } | |
| 25 LocationBarViewMac::~LocationBarViewMac() { } | |
| 26 | |
| 27 void LocationBarViewMac::Init() { | |
| 28 // TODO(shess): deanm indicates that it's likely we will eventually | |
| 29 // get the profile somewhere between point of construction and | |
| 30 // Init(), so mirroring how the gtk code sets this up. | |
| 31 Profile* profile = [[NSApp delegate] defaultProfile]; | |
| 32 edit_view_.reset(new AutocompleteEditViewMac(this, | |
| 33 toolbar_model_, | |
| 34 profile, | |
| 35 command_updater_)); | |
| 36 } | |
| 37 | |
| 38 // TODO(shess): Find a way to get this passed to the constructor. | |
| 39 void LocationBarViewMac::SetField(NSTextField* field) { | |
| 40 edit_view_->SetField(field); | |
| 41 } | |
| 42 | |
| 43 std::wstring LocationBarViewMac::GetInputString() const { | |
| 44 return location_input_; | |
| 45 } | |
| 46 | |
| 47 WindowOpenDisposition LocationBarViewMac::GetWindowOpenDisposition() const { | |
| 48 return disposition_; | |
| 49 } | |
| 50 | |
| 51 // TODO(shess): Verify that this TODO is TODONE. | |
| 52 // TODO(rohitrao): Fix this to return different types once autocomplete and | |
| 53 // the onmibar are implemented. For now, any URL that comes from the | |
| 54 // LocationBar has to have been entered by the user, and thus is of type | |
| 55 // PageTransition::TYPED. | |
| 56 PageTransition::Type LocationBarViewMac::GetPageTransition() const { | |
| 57 return transition_; | |
| 58 } | |
| 59 | |
| 60 void LocationBarViewMac::FocusLocation() { | |
| 61 edit_view_->FocusLocation(); | |
| 62 } | |
| 63 | |
| 64 void LocationBarViewMac::SaveStateToContents(TabContents* contents) { | |
| 65 // TODO(shess): Why SaveStateToContents vs SaveStateToTab? | |
| 66 edit_view_->SaveStateToTab(contents); | |
| 67 } | |
| 68 | |
| 69 void LocationBarViewMac::OnAutocompleteAccept(const GURL& url, | |
| 70 WindowOpenDisposition disposition, | |
| 71 PageTransition::Type transition, | |
| 72 const GURL& alternate_nav_url) { | |
| 73 if (!url.is_valid()) | |
| 74 return; | |
| 75 | |
| 76 location_input_ = UTF8ToWide(url.spec()); | |
| 77 disposition_ = disposition; | |
| 78 transition_ = transition; | |
| 79 | |
| 80 if (!command_updater_) | |
| 81 return; | |
| 82 | |
| 83 if (!alternate_nav_url.is_valid()) { | |
| 84 command_updater_->ExecuteCommand(IDC_OPEN_CURRENT_URL); | |
| 85 return; | |
| 86 } | |
| 87 | |
| 88 scoped_ptr<AlternateNavURLFetcher> fetcher( | |
| 89 new AlternateNavURLFetcher(alternate_nav_url)); | |
| 90 // The AlternateNavURLFetcher will listen for the pending navigation | |
| 91 // notification that will be issued as a result of the "open URL." It | |
| 92 // will automatically install itself into that navigation controller. | |
| 93 command_updater_->ExecuteCommand(IDC_OPEN_CURRENT_URL); | |
| 94 if (fetcher->state() == AlternateNavURLFetcher::NOT_STARTED) { | |
| 95 // I'm not sure this should be reachable, but I'm not also sure enough | |
| 96 // that it shouldn't to stick in a NOTREACHED(). In any case, this is | |
| 97 // harmless; we can simply let the fetcher get deleted here and it will | |
| 98 // clean itself up properly. | |
| 99 } else { | |
| 100 fetcher.release(); // The navigation controller will delete the fetcher. | |
| 101 } | |
| 102 } | |
| 103 | |
| 104 void LocationBarViewMac::OnChanged() { | |
| 105 NOTIMPLEMENTED(); | |
| 106 } | |
| 107 | |
| 108 void LocationBarViewMac::OnInputInProgress(bool in_progress) { | |
| 109 NOTIMPLEMENTED(); | |
| 110 } | |
| 111 | |
| 112 SkBitmap LocationBarViewMac::GetFavIcon() const { | |
| 113 NOTIMPLEMENTED(); | |
| 114 return SkBitmap(); | |
| 115 } | |
| 116 | |
| 117 std::wstring LocationBarViewMac::GetTitle() const { | |
| 118 NOTIMPLEMENTED(); | |
| 119 return std::wstring(); | |
| 120 } | |
| OLD | NEW |