summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa
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
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')
-rw-r--r--chrome/browser/cocoa/location_bar_view_mac.h71
-rw-r--r--chrome/browser/cocoa/location_bar_view_mac.mm120
-rw-r--r--chrome/browser/cocoa/tab_contents_controller.h5
-rw-r--r--chrome/browser/cocoa/tab_contents_controller.mm96
-rw-r--r--chrome/browser/cocoa/tab_strip_controller.mm15
5 files changed, 234 insertions, 73 deletions
diff --git a/chrome/browser/cocoa/location_bar_view_mac.h b/chrome/browser/cocoa/location_bar_view_mac.h
new file mode 100644
index 0000000..f39ff25
--- /dev/null
+++ b/chrome/browser/cocoa/location_bar_view_mac.h
@@ -0,0 +1,71 @@
+// 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 <Cocoa/Cocoa.h>
+
+#include "base/scoped_ptr.h"
+#include "chrome/browser/autocomplete/autocomplete_edit.h"
+#include "chrome/browser/location_bar.h"
+
+class AutocompleteEditViewMac;
+class CommandUpdater;
+class ToolbarModel;
+
+// A C++ bridge class that represents the location bar UI element to
+// the portable code. Wires up an AutocompleteEditViewMac instance to
+// the location bar text field, which handles most of the work.
+
+class LocationBarViewMac : public AutocompleteEditController,
+ public LocationBar {
+ public:
+ LocationBarViewMac(CommandUpdater* command_updater,
+ ToolbarModel* toolbar_model);
+ virtual ~LocationBarViewMac();
+
+ void Init();
+
+ void SetField(NSTextField* field);
+
+ virtual void ShowFirstRunBubble() { NOTIMPLEMENTED(); }
+ virtual std::wstring GetInputString() const;
+ virtual WindowOpenDisposition GetWindowOpenDisposition() const;
+ virtual PageTransition::Type GetPageTransition() const;
+ virtual void AcceptInput() { NOTIMPLEMENTED(); }
+ virtual void AcceptInputWithDisposition(WindowOpenDisposition disposition)
+ { NOTIMPLEMENTED(); }
+ virtual void FocusLocation();
+ virtual void FocusSearch() { NOTIMPLEMENTED(); }
+ virtual void UpdateFeedIcon() { /* http://crbug.com/8832 */ }
+ virtual void SaveStateToContents(TabContents* contents);
+
+ virtual void OnAutocompleteAccept(const GURL& url,
+ WindowOpenDisposition disposition,
+ PageTransition::Type transition,
+ const GURL& alternate_nav_url);
+ virtual void OnChanged();
+ virtual void OnInputInProgress(bool in_progress);
+ virtual SkBitmap GetFavIcon() const;
+ virtual std::wstring GetTitle() const;
+
+ private:
+ scoped_ptr<AutocompleteEditViewMac> edit_view_;
+
+ // TODO(shess): Determine ownership of these. We definitely
+ // shouldn't.
+ CommandUpdater* command_updater_; // weak
+ ToolbarModel* toolbar_model_; // weak
+
+ // When we get an OnAutocompleteAccept notification from the autocomplete
+ // edit, we save the input string so we can give it back to the browser on
+ // the LocationBar interface via GetInputString().
+ std::wstring location_input_;
+
+ // The user's desired disposition for how their input should be opened
+ WindowOpenDisposition disposition_;
+
+ // The transition type to use for the navigation
+ PageTransition::Type transition_;
+
+ DISALLOW_COPY_AND_ASSIGN(LocationBarViewMac);
+};
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();
+}
diff --git a/chrome/browser/cocoa/tab_contents_controller.h b/chrome/browser/cocoa/tab_contents_controller.h
index 3a39b5d..2960588 100644
--- a/chrome/browser/cocoa/tab_contents_controller.h
+++ b/chrome/browser/cocoa/tab_contents_controller.h
@@ -14,6 +14,7 @@
class BookmarkModel;
class CommandUpdater;
class LocationBar;
+class LocationBarViewMac;
class TabContents;
class TabContentsCommandObserver;
class TabStripModel;
@@ -37,7 +38,7 @@ class ToolbarModel;
@private
CommandUpdater* commands_; // weak, may be nil
TabContentsCommandObserver* observer_; // nil if |commands_| is nil
- LocationBar* locationBarBridge_;
+ LocationBarViewMac* locationBarView_;
TabContents* contents_; // weak
ToolbarModel* toolbarModel_; // weak, one per window
@@ -103,6 +104,8 @@ class ToolbarModel;
// state.
- (void)setIsLoading:(BOOL)isLoading;
+- (void)defocusLocationBar;
+
// Make the location bar the first responder, if possible.
- (void)focusLocationBar;
diff --git a/chrome/browser/cocoa/tab_contents_controller.mm b/chrome/browser/cocoa/tab_contents_controller.mm
index a6c1732..a621b0f 100644
--- a/chrome/browser/cocoa/tab_contents_controller.mm
+++ b/chrome/browser/cocoa/tab_contents_controller.mm
@@ -2,19 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/cocoa/tab_contents_controller.h"
+#import "chrome/browser/cocoa/tab_contents_controller.h"
-#import "base/sys_string_conversions.h"
-#import "chrome/app/chrome_dll_resource.h"
-#import "chrome/browser/bookmarks/bookmark_model.h"
-#import "chrome/browser/command_updater.h"
-#import "chrome/browser/location_bar.h"
-#import "chrome/browser/tab_contents/tab_contents.h"
-#import "chrome/browser/toolbar_model.h"
-#import "chrome/browser/net/url_fixer_upper.h"
-
-// For now, tab_contents lives here. TODO(port):fix
-#include "chrome/common/temp_scaffolding_stubs.h"
+#include "base/sys_string_conversions.h"
+#include "chrome/app/chrome_dll_resource.h"
+#include "chrome/browser/bookmarks/bookmark_model.h"
+#import "chrome/browser/cocoa/location_bar_view_mac.h"
+#include "chrome/browser/command_updater.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/browser/toolbar_model.h"
// Names of images in the bundle for the star icon (normal and 'starred').
static NSString* const kStarImageName = @"star";
@@ -24,11 +20,6 @@ static NSString* const kStarredImageName = @"starred";
- (void)enabledStateChangedForCommand:(NSInteger)command enabled:(BOOL)enabled;
@end
-@interface TabContentsController(LocationBar)
-- (NSString*)locationBarString;
-- (void)focusLocationBar;
-@end
-
@interface TabContentsController(Private)
- (void)updateToolbarCommandStatus;
- (void)applyContentsBoxOffset:(BOOL)apply;
@@ -50,36 +41,6 @@ class TabContentsCommandObserver : public CommandUpdater::CommandObserver {
CommandUpdater* commands_; // weak
};
-// A C++ bridge class that handles responding to requests from the
-// cross-platform code for information about the location bar. Just passes
-// everything back to the controller.
-class LocationBarBridge : public LocationBar {
- public:
- LocationBarBridge(TabContentsController* controller);
-
- // Overridden from LocationBar
- virtual void ShowFirstRunBubble() { NOTIMPLEMENTED(); }
- virtual std::wstring GetInputString() const;
- virtual WindowOpenDisposition GetWindowOpenDisposition() const
- { NOTIMPLEMENTED(); return CURRENT_TAB; }
- // 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.
- virtual PageTransition::Type GetPageTransition() const
- { NOTIMPLEMENTED(); return PageTransition::TYPED; }
- virtual void AcceptInput() { NOTIMPLEMENTED(); }
- virtual void AcceptInputWithDisposition(WindowOpenDisposition disposition)
- { NOTIMPLEMENTED(); }
- virtual void FocusLocation();
- virtual void FocusSearch() { NOTIMPLEMENTED(); }
- virtual void UpdateFeedIcon() { /* http://crbug.com/8832 */ }
- virtual void SaveStateToContents(TabContents* contents) { NOTIMPLEMENTED(); }
-
- private:
- TabContentsController* controller_; // weak, owns me
-};
-
@implementation TabContentsController
- (id)initWithNibName:(NSString*)name
@@ -92,7 +53,7 @@ class LocationBarBridge : public LocationBar {
commands_ = commands;
if (commands_)
observer_ = new TabContentsCommandObserver(self, commands);
- locationBarBridge_ = new LocationBarBridge(self);
+ locationBarView_ = new LocationBarViewMac(commands, toolbarModel);
contents_ = contents;
toolbarModel_ = toolbarModel;
bookmarkModel_ = bookmarkModel;
@@ -104,7 +65,7 @@ class LocationBarBridge : public LocationBar {
// make sure our contents have been removed from the window
[[self view] removeFromSuperview];
delete observer_;
- delete locationBarBridge_;
+ delete locationBarView_;
[super dealloc];
}
@@ -116,11 +77,18 @@ class LocationBarBridge : public LocationBar {
// doesn't change between tabs.
[self updateToolbarCommandStatus];
+ // TODO(shess): This code doesn't have locationBar_ when
+ // locationBarView_ is constructed, so we need the SetField() helper to
+ // pass in the object here. Consider refactoring to obsolete that
+ // helper, perhaps by not constructing locationBarView_ until we have
+ // locationBar_.
+ locationBarView_->Init();
+ locationBarView_->SetField(locationBar_);
[locationBar_ setStringValue:@"http://dev.chromium.org"];
}
- (LocationBar*)locationBar {
- return locationBarBridge_;
+ return locationBarView_;
}
// Returns YES if the tab represented by this controller is the front-most.
@@ -188,12 +156,12 @@ class LocationBarBridge : public LocationBar {
[contentsBox_ setContentView:contents_->GetNativeView()];
}
-- (NSString*)locationBarString {
- return [locationBar_ stringValue];
+- (void)defocusLocationBar {
+ locationBarView_->SaveStateToContents(NULL);
}
- (void)focusLocationBar {
- [[locationBar_ window] makeFirstResponder:locationBar_];
+ locationBarView_->FocusLocation();
}
- (void)updateToolbarWithContents:(TabContents*)tab {
@@ -202,6 +170,9 @@ class LocationBarBridge : public LocationBar {
// TODO(pinkerton): update the security lock icon and background color
+ // TODO(shess): Determine whether this should happen via
+ // locationBarView_, instead, in which case this class can
+ // potentially lose the locationBar_ reference.
NSString* urlString = base::SysWideToNSString(toolbarModel_->GetText());
[locationBar_ setStringValue:urlString];
}
@@ -312,22 +283,3 @@ void TabContentsCommandObserver::EnabledStateChangedForCommand(int command,
[controller_ enabledStateChangedForCommand:command
enabled:enabled ? YES : NO];
}
-
-//--------------------------------------------------------------------------
-
-LocationBarBridge::LocationBarBridge(TabContentsController* controller)
- : controller_(controller) {
-}
-
-std::wstring LocationBarBridge::GetInputString() const {
- // TODO(shess): This code is temporary until the omnibox code takes
- // over.
- std::wstring url = base::SysNSStringToWide([controller_ locationBarString]);
-
- // Try to flesh out the input to make a real URL.
- return URLFixerUpper::FixupURL(url, std::wstring());
-}
-
-void LocationBarBridge::FocusLocation() {
- [controller_ focusLocationBar];
-}
diff --git a/chrome/browser/cocoa/tab_strip_controller.mm b/chrome/browser/cocoa/tab_strip_controller.mm
index 46a98df..28678d7 100644
--- a/chrome/browser/cocoa/tab_strip_controller.mm
+++ b/chrome/browser/cocoa/tab_strip_controller.mm
@@ -295,6 +295,14 @@ class TabStripBridge : public TabStripModelObserver {
previousContents:(TabContents*)oldContents
atIndex:(NSInteger)index
userGesture:(bool)wasUserGesture {
+ int selectedIndex = 0;
+ for (TabController* current in tabArray_) {
+ if ([current selected]) {
+ break;
+ }
+ ++selectedIndex;
+ }
+
// De-select all other tabs and select the new tab.
int i = 0;
for (TabController* current in tabArray_) {
@@ -306,6 +314,13 @@ class TabStripBridge : public TabStripModelObserver {
NSView* selectedTab = [self viewAtIndex:index];
[tabView_ addSubview:selectedTab positioned:NSWindowAbove relativeTo:nil];
+ // Tell the current tab to lose focus.
+ if (selectedIndex < (int)[tabArray_ count]) {
+ TabContentsController* selectedController =
+ [tabContentsArray_ objectAtIndex:selectedIndex];
+ [selectedController defocusLocationBar];
+ }
+
// Tell the new tab contents it is about to become the selected tab. Here it
// can do things like make sure the toolbar is up to date.
TabContentsController* newController =