summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-08 04:53:50 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-08 04:53:50 +0000
commita1481e294812aab9b6050db712669d2b75fea5a4 (patch)
treef3aabc41eafde15154a3c335fad39be6b648f320 /chrome
parent8ff8763e823b748b56c5c688568cd1b449cf3465 (diff)
downloadchromium_src-a1481e294812aab9b6050db712669d2b75fea5a4.zip
chromium_src-a1481e294812aab9b6050db712669d2b75fea5a4.tar.gz
chromium_src-a1481e294812aab9b6050db712669d2b75fea5a4.tar.bz2
Move location bar bridge out of tab_contents_controller.
[So that I don't keep getting conflicts as I work to finish the omnibox change http://codereview.chromium.org/50074 ] Review URL: http://codereview.chromium.org/63096 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13342 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/cocoa/location_bar_view_mac.h52
-rw-r--r--chrome/browser/cocoa/location_bar_view_mac.mm34
-rw-r--r--chrome/browser/cocoa/location_bar_view_mac_unittest.mm42
-rw-r--r--chrome/browser/cocoa/tab_contents_controller.h3
-rw-r--r--chrome/browser/cocoa/tab_contents_controller.mm90
-rw-r--r--chrome/chrome.gyp3
6 files changed, 149 insertions, 75 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..2e32afc
--- /dev/null
+++ b/chrome/browser/cocoa/location_bar_view_mac.h
@@ -0,0 +1,52 @@
+// 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.
+
+#ifndef CHROME_BROWSER_COCOA_LOCATION_BAR_VIEW_MAC_H_
+#define CHROME_BROWSER_COCOA_LOCATION_BAR_VIEW_MAC_H_
+
+#import <Cocoa/Cocoa.h>
+
+#include "chrome/browser/location_bar.h"
+
+// A C++ bridge class that handles responding to requests from the
+// cross-platform code for information about the location bar.
+
+class LocationBarViewMac : public LocationBar {
+ public:
+ LocationBarViewMac(NSTextField* field);
+ virtual ~LocationBarViewMac();
+
+ // TODO(shess): This is a placeholder for the Omnibox code. The
+ // problem it will paper over is that Profile availability does not
+ // match object creation in TabContentsController. Circle back and
+ // resolve this after the Profile-handling and tab logic changes are
+ // complete.
+ void Init();
+
+ // 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:
+ NSTextField* field_; // weak, owned by TabContentsController
+
+ DISALLOW_COPY_AND_ASSIGN(LocationBarViewMac);
+};
+
+#endif // CHROME_BROWSER_COCOA_LOCATION_BAR_VIEW_MAC_H_
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..ed660b9
--- /dev/null
+++ b/chrome/browser/cocoa/location_bar_view_mac.mm
@@ -0,0 +1,34 @@
+// 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/sys_string_conversions.h"
+#include "chrome/browser/net/url_fixer_upper.h"
+
+LocationBarViewMac::LocationBarViewMac(NSTextField* field)
+ : field_(field) {
+ // TODO(shess): Placeholder for omnibox changes.
+}
+
+LocationBarViewMac::~LocationBarViewMac() {
+ // TODO(shess): Placeholder for omnibox changes.
+}
+
+void LocationBarViewMac::Init() {
+ // TODO(shess): Placeholder for omnibox changes.
+}
+
+std::wstring LocationBarViewMac::GetInputString() const {
+ // TODO(shess): This code is temporary until the omnibox code takes
+ // over.
+ std::wstring url = base::SysNSStringToWide([field_ stringValue]);
+
+ // Try to flesh out the input to make a real URL.
+ return URLFixerUpper::FixupURL(url, std::wstring());
+}
+
+void LocationBarViewMac::FocusLocation() {
+ [[field_ window] makeFirstResponder:field_];
+}
diff --git a/chrome/browser/cocoa/location_bar_view_mac_unittest.mm b/chrome/browser/cocoa/location_bar_view_mac_unittest.mm
new file mode 100644
index 0000000..f84b15b1
--- /dev/null
+++ b/chrome/browser/cocoa/location_bar_view_mac_unittest.mm
@@ -0,0 +1,42 @@
+// 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.
+
+#include "base/scoped_nsobject.h"
+#include "base/scoped_ptr.h"
+#include "base/string_util.h"
+#include "chrome/browser/cocoa/location_bar_view_mac.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class LocationBarViewMacTest : public testing::Test {
+ public:
+ LocationBarViewMacTest()
+ : field_([[NSTextField alloc] init]),
+ locationBarView_(new LocationBarViewMac(field_)) {
+ }
+
+ scoped_nsobject<NSTextField> field_;
+ scoped_ptr<LocationBarViewMac> locationBarView_;
+};
+
+TEST_F(LocationBarViewMacTest, GetInputString) {
+ // Test a few obvious cases to make sure things work end-to-end, but
+ // trust url_fixer_upper_unittest.cc to do the bulk of the work.
+ [field_ setStringValue:@"ahost"];
+ EXPECT_EQ(locationBarView_->GetInputString(), ASCIIToWide("http://ahost/"));
+
+ [field_ setStringValue:@"bhost\n"];
+ EXPECT_EQ(locationBarView_->GetInputString(), ASCIIToWide("http://bhost/"));
+
+ [field_ setStringValue:@"chost/"];
+ EXPECT_EQ(locationBarView_->GetInputString(), ASCIIToWide("http://chost/"));
+
+ [field_ setStringValue:@"www.example.com"];
+ EXPECT_EQ(locationBarView_->GetInputString(), ASCIIToWide("http://www.example.com/"));
+
+ [field_ setStringValue:@"http://example.com"];
+ EXPECT_EQ(locationBarView_->GetInputString(), ASCIIToWide("http://example.com/"));
+
+ [field_ setStringValue:@"https://www.example.com"];
+ EXPECT_EQ(locationBarView_->GetInputString(), ASCIIToWide("https://www.example.com/"));
+}
diff --git a/chrome/browser/cocoa/tab_contents_controller.h b/chrome/browser/cocoa/tab_contents_controller.h
index 3a39b5d..bf97dc3 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
diff --git a/chrome/browser/cocoa/tab_contents_controller.mm b/chrome/browser/cocoa/tab_contents_controller.mm
index a6c1732..1ceb2a3 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,6 @@ class LocationBarBridge : public LocationBar {
commands_ = commands;
if (commands_)
observer_ = new TabContentsCommandObserver(self, commands);
- locationBarBridge_ = new LocationBarBridge(self);
contents_ = contents;
toolbarModel_ = toolbarModel;
bookmarkModel_ = bookmarkModel;
@@ -104,7 +64,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 +76,14 @@ class LocationBarBridge : public LocationBar {
// doesn't change between tabs.
[self updateToolbarCommandStatus];
+ locationBarView_ = new LocationBarViewMac(locationBar_);
+ locationBarView_->Init();
+
[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 +151,10 @@ class LocationBarBridge : public LocationBar {
[contentsBox_ setContentView:contents_->GetNativeView()];
}
-- (NSString*)locationBarString {
- return [locationBar_ stringValue];
-}
-
- (void)focusLocationBar {
- [[locationBar_ window] makeFirstResponder:locationBar_];
+ if (locationBarView_) {
+ locationBarView_->FocusLocation();
+ }
}
- (void)updateToolbarWithContents:(TabContents*)tab {
@@ -312,22 +273,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/chrome.gyp b/chrome/chrome.gyp
index d97982f..8fe9522 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -525,6 +525,8 @@
'browser/cocoa/browser_window_controller.mm',
'browser/cocoa/grow_box_view.h',
'browser/cocoa/grow_box_view.m',
+ 'browser/cocoa/location_bar_view_mac.h',
+ 'browser/cocoa/location_bar_view_mac.mm',
'browser/cocoa/sad_tab_view.h',
'browser/cocoa/sad_tab_view.mm',
'browser/cocoa/shell_dialogs_mac.mm',
@@ -2086,6 +2088,7 @@
'browser/cocoa/bookmark_bar_state_controller_unittest.mm',
'browser/cocoa/bookmark_menu_bridge_unittest.mm',
'browser/cocoa/bookmark_menu_cocoa_controller_unittest.mm',
+ 'browser/cocoa/location_bar_view_mac_unittest.mm',
'browser/command_updater_unittest.cc',
'browser/debugger/devtools_manager_unittest.cc',
'browser/dom_ui/dom_ui_unittest.cc',