summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-11 21:47:01 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-11 21:47:01 +0000
commit394aa59248445297e01bf09acc40c2ff0fb34999 (patch)
treee9549ea2649db32eba6ddb39e277ddbd3e34b492 /chrome/browser/cocoa
parent2afc8336851ae77cfc681c8823d1c478364a4cd3 (diff)
downloadchromium_src-394aa59248445297e01bf09acc40c2ff0fb34999.zip
chromium_src-394aa59248445297e01bf09acc40c2ff0fb34999.tar.gz
chromium_src-394aa59248445297e01bf09acc40c2ff0fb34999.tar.bz2
Use Chrome facilities for omnibox state save and restore on Mac.
TabContents has a facility for storing a bag of stuff across current-tab changes. Wire up AutocompleteEditViewMac to use that facility. Unfork some code in Browser::TabSelectedAt() so that the new code gets used, and straighten up the Mac code along the code path between there and AutocompleteEditViewMac. This overall change also exposed a couple bugs/mis-features in the AutocompleteEditViewMac code. TEST=Text field maintains contents and selection across tab changes, even when edited. Review URL: http://codereview.chromium.org/114017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15790 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r--chrome/browser/cocoa/browser_window_controller.mm3
-rw-r--r--chrome/browser/cocoa/location_bar_view_mac.h5
-rw-r--r--chrome/browser/cocoa/location_bar_view_mac.mm6
-rw-r--r--chrome/browser/cocoa/toolbar_controller.h9
-rw-r--r--chrome/browser/cocoa/toolbar_controller.mm25
5 files changed, 22 insertions, 26 deletions
diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm
index 08250f1..c0150d5f 100644
--- a/chrome/browser/cocoa/browser_window_controller.mm
+++ b/chrome/browser/cocoa/browser_window_controller.mm
@@ -290,7 +290,8 @@ willPositionSheet:(NSWindow *)sheet
- (void)updateToolbarWithContents:(TabContents*)tab
shouldRestoreState:(BOOL)shouldRestore {
- [toolbarController_ updateToolbarWithContents:shouldRestore ? tab : NULL];
+ [toolbarController_ updateToolbarWithContents:tab
+ shouldRestoreState:shouldRestore];
}
- (void)setStarredState:(BOOL)isStarred {
diff --git a/chrome/browser/cocoa/location_bar_view_mac.h b/chrome/browser/cocoa/location_bar_view_mac.h
index ee9cf26..12f32fa 100644
--- a/chrome/browser/cocoa/location_bar_view_mac.h
+++ b/chrome/browser/cocoa/location_bar_view_mac.h
@@ -46,6 +46,11 @@ class LocationBarViewMac : public AutocompleteEditController,
return edit_view_.get();
}
+ // Updates the location bar. Resets the bar's permanent text and
+ // security style, and if |should_restore_state| is true, restores
+ // saved state from the tab (for tab switching).
+ void Update(const TabContents* tab, bool should_restore_state);
+
virtual void OnAutocompleteAccept(const GURL& url,
WindowOpenDisposition disposition,
PageTransition::Type transition,
diff --git a/chrome/browser/cocoa/location_bar_view_mac.mm b/chrome/browser/cocoa/location_bar_view_mac.mm
index b8c521f..138a567 100644
--- a/chrome/browser/cocoa/location_bar_view_mac.mm
+++ b/chrome/browser/cocoa/location_bar_view_mac.mm
@@ -56,6 +56,12 @@ void LocationBarViewMac::SaveStateToContents(TabContents* contents) {
edit_view_->SaveStateToTab(contents);
}
+void LocationBarViewMac::Update(const TabContents* contents,
+ bool should_restore_state) {
+ // AutocompleteEditView restores state if the tab is non-NULL.
+ edit_view_->Update(should_restore_state ? contents : NULL);
+}
+
void LocationBarViewMac::OnAutocompleteAccept(const GURL& url,
WindowOpenDisposition disposition,
PageTransition::Type transition,
diff --git a/chrome/browser/cocoa/toolbar_controller.h b/chrome/browser/cocoa/toolbar_controller.h
index 8967aee..1909800 100644
--- a/chrome/browser/cocoa/toolbar_controller.h
+++ b/chrome/browser/cocoa/toolbar_controller.h
@@ -52,9 +52,12 @@ class ToolbarView;
// Make the location bar the first responder, if possible.
- (void)focusLocationBar;
-// Called when any url bar state changes. If |tabForRestoring| is non-NULL,
-// it points to a TabContents whose state we should restore.
-- (void)updateToolbarWithContents:(TabContents*)tabForRestoring;
+// Updates the toolbar (and transitively the location bar) with the states of
+// the specified |tab|. If |shouldRestore| is true, we're switching
+// (back?) to this tab and should restore any previous location bar state
+// (such as user editing) as well.
+- (void)updateToolbarWithContents:(TabContents*)tabForRestoring
+ shouldRestoreState:(BOOL)shouldRestore;
// Sets whether or not the current page in the frontmost tab is bookmarked.
- (void)setStarredState:(BOOL)isStarred;
diff --git a/chrome/browser/cocoa/toolbar_controller.mm b/chrome/browser/cocoa/toolbar_controller.mm
index d2a986e..0860a0b 100644
--- a/chrome/browser/cocoa/toolbar_controller.mm
+++ b/chrome/browser/cocoa/toolbar_controller.mm
@@ -48,7 +48,6 @@ static NSString* const kStarredImageName = @"starred";
[self initCommandStatus:commands_];
locationBarView_.reset(new LocationBarViewMac(locationBar_, commands_,
toolbarModel_, profile_));
- [locationBar_ setStringValue:@"http://dev.chromium.org"];
}
- (void)dealloc {
@@ -98,27 +97,9 @@ static NSString* const kStarredImageName = @"starred";
[starButton_ setEnabled:commands->IsCommandEnabled(IDC_STAR) ? YES : NO];
}
-- (void)updateToolbarWithContents:(TabContents*)tab {
- // TODO(pinkerton): there's a lot of ui code in autocomplete_edit.cc
- // that we'll want to duplicate. For now, just handle setting the text.
-
- // TODO(shess): This is the start of what pinkerton refers to.
- // Unfortunately, I'm going to need to spend some time wiring things
- // up. This call should suffice to close any open autocomplete
- // pulldown. It should also be the right thing to do to save and
- // restore state, but at this time it's not clear that this is the
- // right place, and tab is not the right parameter.
- if (locationBarView_.get()) {
- locationBarView_->SaveStateToContents(NULL);
- }
-
- // 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];
+- (void)updateToolbarWithContents:(TabContents*)tab
+ shouldRestoreState:(BOOL)shouldRestore {
+ locationBarView_->Update(tab, shouldRestore ? true : false);
}
- (void)setStarredState:(BOOL)isStarred {