summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/location_bar_view_mac.mm
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-06 22:51:11 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-06 22:51:11 +0000
commit5856887365d0b2a48ed2c5d160b50904959edb59 (patch)
tree8684e18b08031dff4a953a3c07f63795bbbdb729 /chrome/browser/cocoa/location_bar_view_mac.mm
parente713032402418e679b6ad93f75ac33e879b9ceee (diff)
downloadchromium_src-5856887365d0b2a48ed2c5d160b50904959edb59.zip
chromium_src-5856887365d0b2a48ed2c5d160b50904959edb59.tar.gz
chromium_src-5856887365d0b2a48ed2c5d160b50904959edb59.tar.bz2
Initial implemention of Mac Omnibox.
AutocompletePopupViewMac implements AutocompletePopupView in terms of a bare NSWindow containing an NSTableView. AutocompleteTableTarget implements an Obj-C class to bridge from appkit callbacks back to the popup view (and from there to the model which contains the data it needs). AutocompleteEditViewMac implements AutocompleteEditView in terms of an NSTextField, which is passed down from a nib owner. It works with the popup view to make sure the popup is positioned correctly. AutocompleteFieldDelegate is an internal Obj-C class to bridge from appkit callbacks back to the edit view (and then the edit model). LocationBarViewMac implements LocationBar for interacting with the rest of the browser, and AutocompleteEditController for managing the edit and popup views. It is mostly placeholder code stolen from the gtk implementation. --- I've tried to implement an amount of code which worked and was useful, but which didn't drag on and on into the future. So no tab to search or hints or anything, sometimes ugly, selection may be funky, etc. Review URL: http://codereview.chromium.org/50074 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13201 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/location_bar_view_mac.mm')
-rw-r--r--chrome/browser/cocoa/location_bar_view_mac.mm120
1 files changed, 120 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/location_bar_view_mac.mm b/chrome/browser/cocoa/location_bar_view_mac.mm
new file mode 100644
index 0000000..a70fd9c
--- /dev/null
+++ b/chrome/browser/cocoa/location_bar_view_mac.mm
@@ -0,0 +1,120 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "chrome/browser/cocoa/location_bar_view_mac.h"
+
+#include "base/string_util.h"
+#include "chrome/app/chrome_dll_resource.h"
+#include "chrome/browser/alternate_nav_url_fetcher.h"
+#import "chrome/browser/app_controller_mac.h"
+#import "chrome/browser/autocomplete/autocomplete_edit_view_mac.h"
+#include "chrome/browser/command_updater.h"
+#include "skia/include/SkBitmap.h"
+
+// TODO(shess): This code is mostly copied from the gtk
+// implementation. Make sure it's all appropriate and flesh it out.
+
+LocationBarViewMac::LocationBarViewMac(CommandUpdater* command_updater,
+ ToolbarModel* toolbar_model)
+ : command_updater_(command_updater),
+ toolbar_model_(toolbar_model),
+ disposition_(CURRENT_TAB),
+ transition_(PageTransition::TYPED) {
+}
+LocationBarViewMac::~LocationBarViewMac() { }
+
+void LocationBarViewMac::Init() {
+ // TODO(shess): deanm indicates that it's likely we will eventually
+ // get the profile somewhere between point of construction and
+ // Init(), so mirroring how the gtk code sets this up.
+ Profile* profile = [[NSApp delegate] defaultProfile];
+ edit_view_.reset(new AutocompleteEditViewMac(this,
+ toolbar_model_,
+ profile,
+ command_updater_));
+}
+
+// TODO(shess): Find a way to get this passed to the constructor.
+void LocationBarViewMac::SetField(NSTextField* field) {
+ edit_view_->SetField(field);
+}
+
+std::wstring LocationBarViewMac::GetInputString() const {
+ return location_input_;
+}
+
+WindowOpenDisposition LocationBarViewMac::GetWindowOpenDisposition() const {
+ return disposition_;
+}
+
+// TODO(shess): Verify that this TODO is TODONE.
+// TODO(rohitrao): Fix this to return different types once autocomplete and
+// the onmibar are implemented. For now, any URL that comes from the
+// LocationBar has to have been entered by the user, and thus is of type
+// PageTransition::TYPED.
+PageTransition::Type LocationBarViewMac::GetPageTransition() const {
+ return transition_;
+}
+
+void LocationBarViewMac::FocusLocation() {
+ edit_view_->FocusLocation();
+}
+
+void LocationBarViewMac::SaveStateToContents(TabContents* contents) {
+ // TODO(shess): Why SaveStateToContents vs SaveStateToTab?
+ edit_view_->SaveStateToTab(contents);
+}
+
+void LocationBarViewMac::OnAutocompleteAccept(const GURL& url,
+ WindowOpenDisposition disposition,
+ PageTransition::Type transition,
+ const GURL& alternate_nav_url) {
+ if (!url.is_valid())
+ return;
+
+ location_input_ = UTF8ToWide(url.spec());
+ disposition_ = disposition;
+ transition_ = transition;
+
+ if (!command_updater_)
+ return;
+
+ if (!alternate_nav_url.is_valid()) {
+ command_updater_->ExecuteCommand(IDC_OPEN_CURRENT_URL);
+ return;
+ }
+
+ scoped_ptr<AlternateNavURLFetcher> fetcher(
+ new AlternateNavURLFetcher(alternate_nav_url));
+ // The AlternateNavURLFetcher will listen for the pending navigation
+ // notification that will be issued as a result of the "open URL." It
+ // will automatically install itself into that navigation controller.
+ command_updater_->ExecuteCommand(IDC_OPEN_CURRENT_URL);
+ if (fetcher->state() == AlternateNavURLFetcher::NOT_STARTED) {
+ // I'm not sure this should be reachable, but I'm not also sure enough
+ // that it shouldn't to stick in a NOTREACHED(). In any case, this is
+ // harmless; we can simply let the fetcher get deleted here and it will
+ // clean itself up properly.
+ } else {
+ fetcher.release(); // The navigation controller will delete the fetcher.
+ }
+}
+
+void LocationBarViewMac::OnChanged() {
+ NOTIMPLEMENTED();
+}
+
+void LocationBarViewMac::OnInputInProgress(bool in_progress) {
+ NOTIMPLEMENTED();
+}
+
+SkBitmap LocationBarViewMac::GetFavIcon() const {
+ NOTIMPLEMENTED();
+ return SkBitmap();
+}
+
+std::wstring LocationBarViewMac::GetTitle() const {
+ NOTIMPLEMENTED();
+ return std::wstring();
+}