summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/tab_contents_controller.mm
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/cocoa/tab_contents_controller.mm')
-rw-r--r--chrome/browser/cocoa/tab_contents_controller.mm96
1 files changed, 72 insertions, 24 deletions
diff --git a/chrome/browser/cocoa/tab_contents_controller.mm b/chrome/browser/cocoa/tab_contents_controller.mm
index a621b0f..a6c1732 100644
--- a/chrome/browser/cocoa/tab_contents_controller.mm
+++ b/chrome/browser/cocoa/tab_contents_controller.mm
@@ -2,15 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#import "chrome/browser/cocoa/tab_contents_controller.h"
+#include "chrome/browser/cocoa/tab_contents_controller.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"
+#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"
// Names of images in the bundle for the star icon (normal and 'starred').
static NSString* const kStarImageName = @"star";
@@ -20,6 +24,11 @@ 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;
@@ -41,6 +50,36 @@ 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
@@ -53,7 +92,7 @@ class TabContentsCommandObserver : public CommandUpdater::CommandObserver {
commands_ = commands;
if (commands_)
observer_ = new TabContentsCommandObserver(self, commands);
- locationBarView_ = new LocationBarViewMac(commands, toolbarModel);
+ locationBarBridge_ = new LocationBarBridge(self);
contents_ = contents;
toolbarModel_ = toolbarModel;
bookmarkModel_ = bookmarkModel;
@@ -65,7 +104,7 @@ class TabContentsCommandObserver : public CommandUpdater::CommandObserver {
// make sure our contents have been removed from the window
[[self view] removeFromSuperview];
delete observer_;
- delete locationBarView_;
+ delete locationBarBridge_;
[super dealloc];
}
@@ -77,18 +116,11 @@ class TabContentsCommandObserver : public CommandUpdater::CommandObserver {
// 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 locationBarView_;
+ return locationBarBridge_;
}
// Returns YES if the tab represented by this controller is the front-most.
@@ -156,12 +188,12 @@ class TabContentsCommandObserver : public CommandUpdater::CommandObserver {
[contentsBox_ setContentView:contents_->GetNativeView()];
}
-- (void)defocusLocationBar {
- locationBarView_->SaveStateToContents(NULL);
+- (NSString*)locationBarString {
+ return [locationBar_ stringValue];
}
- (void)focusLocationBar {
- locationBarView_->FocusLocation();
+ [[locationBar_ window] makeFirstResponder:locationBar_];
}
- (void)updateToolbarWithContents:(TabContents*)tab {
@@ -170,9 +202,6 @@ class TabContentsCommandObserver : public CommandUpdater::CommandObserver {
// 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];
}
@@ -283,3 +312,22 @@ 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];
+}