diff options
author | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-09 18:44:51 +0000 |
---|---|---|
committer | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-09 18:44:51 +0000 |
commit | 16e785bf7ae2d1910d38e0e5843acd4648d50b21 (patch) | |
tree | 083c57b51daa703772ada68ed65a19e616a59e4a /chrome/browser/cocoa/toolbar_controller.mm | |
parent | 95b9162bf10740841d7803bcb978b87f52bfea3e (diff) | |
download | chromium_src-16e785bf7ae2d1910d38e0e5843acd4648d50b21.zip chromium_src-16e785bf7ae2d1910d38e0e5843acd4648d50b21.tar.gz chromium_src-16e785bf7ae2d1910d38e0e5843acd4648d50b21.tar.bz2 |
Flatten down to a single toolbar per window, significantly simplifying the tab strip as it now no longer needs to forward messages for everything. Created a toolbar controller to encapsulate much of the toolbar logic that was in the tab contents controller. Better parameterized the tab strip controller so that it could switch any view, not just the main window's content view, when switching tabs.
Review URL: http://codereview.chromium.org/65011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13441 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/toolbar_controller.mm')
-rw-r--r-- | chrome/browser/cocoa/toolbar_controller.mm | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/toolbar_controller.mm b/chrome/browser/cocoa/toolbar_controller.mm new file mode 100644 index 0000000..e77c30c --- /dev/null +++ b/chrome/browser/cocoa/toolbar_controller.mm @@ -0,0 +1,123 @@ +// 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/toolbar_controller.h" + +#include "base/sys_string_conversions.h" +#include "chrome/app/chrome_dll_resource.h" +#import "chrome/browser/cocoa/location_bar_view_mac.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"; +static NSString* const kStarredImageName = @"starred"; + +@interface ToolbarController(Private) +- (void)initCommandStatus:(CommandUpdater*)commands; +@end + +@implementation ToolbarController + +- (id)initWithModel:(ToolbarModel*)model + commands:(CommandUpdater*)commands { + DCHECK(model && commands); + if ((self = [super initWithNibName:@"Toolbar" bundle:nil])) { + toolbarModel_ = model; + commands_ = commands; + + // Register for notifications about state changes for the toolbar buttons + commandObserver_ = new CommandObserverBridge(self, commands); + commandObserver_->ObserveCommand(IDC_BACK); + commandObserver_->ObserveCommand(IDC_FORWARD); + commandObserver_->ObserveCommand(IDC_RELOAD); + commandObserver_->ObserveCommand(IDC_HOME); + commandObserver_->ObserveCommand(IDC_STAR); + } + return self; +} + +// Called after the view is done loading and the outlets have been hooked up. +// Now we can hook up bridges that rely on UI objects such as the location +// bar and button state. +- (void)awakeFromNib { + [self initCommandStatus:commands_]; + locationBarView_ = new LocationBarViewMac(locationBar_); + locationBarView_->Init(); + [locationBar_ setStringValue:@"http://dev.chromium.org"]; +} + +- (void)dealloc { + delete locationBarView_; + delete commandObserver_; + [super dealloc]; +} + +- (LocationBar*)locationBar { + return locationBarView_; +} + +- (void)focusLocationBar { + if (locationBarView_) { + locationBarView_->FocusLocation(); + } +} + +// Called when the state for a command changes to |enabled|. Update the +// corresponding UI element. +- (void)enabledStateChangedForCommand:(NSInteger)command enabled:(BOOL)enabled { + NSButton* button = nil; + switch (command) { + case IDC_BACK: + button = backButton_; + break; + case IDC_FORWARD: + button = forwardButton_; + break; + case IDC_HOME: + // TODO(pinkerton): add home button + break; + case IDC_STAR: + button = starButton_; + break; + } + [button setEnabled:enabled]; +} + +// Init the enabled state of the buttons on the toolbar to match the state in +// the controller. +- (void)initCommandStatus:(CommandUpdater*)commands { + [backButton_ setEnabled:commands->IsCommandEnabled(IDC_BACK) ? YES : NO]; + [forwardButton_ + setEnabled:commands->IsCommandEnabled(IDC_FORWARD) ? YES : NO]; + [reloadButton_ + setEnabled:commands->IsCommandEnabled(IDC_RELOAD) ? YES : NO]; + // TODO(pinkerton): Add home button. + [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(pinkerton): update the security lock icon and background color + + NSString* urlString = base::SysWideToNSString(toolbarModel_->GetText()); + [locationBar_ setStringValue:urlString]; +} + +- (void)setStarredState:(BOOL)isStarred { + NSString* starImageName = kStarImageName; + if (isStarred) + starImageName = kStarredImageName; + [starButton_ setImage:[NSImage imageNamed:starImageName]]; +} + +- (void)setIsLoading:(BOOL)isLoading { + NSString* imageName = @"go"; + if (isLoading) + imageName = @"stop"; + [goButton_ setImage:[NSImage imageNamed:imageName]]; +} + +@end |