Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: chrome/browser/cocoa/toolbar_controller.mm

Issue 65011: Flatten down to a single toolbar per window, significantly simplifying the ta... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Name: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "chrome/browser/cocoa/toolbar_controller.h"
6
7 #include "base/sys_string_conversions.h"
8 #include "chrome/app/chrome_dll_resource.h"
9 #import "chrome/browser/cocoa/location_bar_view_mac.h"
10 #include "chrome/browser/toolbar_model.h"
11
12 // Names of images in the bundle for the star icon (normal and 'starred').
13 static NSString* const kStarImageName = @"star";
14 static NSString* const kStarredImageName = @"starred";
15
16 @interface ToolbarController(Private)
17 - (void)initCommandStatus:(CommandUpdater*)commands;
18 @end
19
20 @implementation ToolbarController
21
22 - (id)initWithModel:(ToolbarModel*)model
23 commands:(CommandUpdater*)commands {
24 if ((self = [super initWithNibName:@"Toolbar" bundle:nil])) {
TVL 2009/04/09 15:53:00 dcheck model and commands like the other classes d
pink (ping after 24hrs) 2009/04/09 16:00:48 Done.
25 toolbarModel_ = model;
26 commands_ = commands;
27
28 // Register for notifications about state changes for the toolbar buttons
29 commandObserver_ = new CommandObserverBridge(self, commands);
30 commandObserver_->ObserveCommand(IDC_BACK);
31 commandObserver_->ObserveCommand(IDC_FORWARD);
32 commandObserver_->ObserveCommand(IDC_RELOAD);
33 commandObserver_->ObserveCommand(IDC_HOME);
34 commandObserver_->ObserveCommand(IDC_STAR);
35 }
36 return self;
37 }
38
39 // Called after the view is done loading and the outlets have been hooked up.
40 // Now we can hook up bridges that rely on UI objects such as the location
41 // bar and button state.
42 - (void)awakeFromNib {
43 [self initCommandStatus:commands_];
44 locationBarView_ = new LocationBarViewMac(locationBar_);
45 locationBarView_->Init();
46 [locationBar_ setStringValue:@"http://dev.chromium.org"];
47 }
48
49 - (void)dealloc {
50 delete locationBarView_;
51 delete commandObserver_;
52 [super dealloc];
53 }
54
55 - (LocationBar*)locationBar {
56 return locationBarView_;
57 }
58
59 - (void)focusLocationBar {
60 if (locationBarView_) {
61 locationBarView_->FocusLocation();
62 }
63 }
64
65 // Called when the state for a command changes to |enabled|. Update the
66 // corresponding UI element.
67 - (void)enabledStateChangedForCommand:(NSInteger)command enabled:(BOOL)enabled {
68 NSButton* button = nil;
69 switch (command) {
70 case IDC_BACK:
71 button = backButton_;
72 break;
73 case IDC_FORWARD:
74 button = forwardButton_;
75 break;
76 case IDC_HOME:
77 // TODO(pinkerton): add home button
78 break;
79 case IDC_STAR:
80 button = starButton_;
81 break;
TVL 2009/04/09 15:53:00 fix the indents here
pink (ping after 24hrs) 2009/04/09 16:00:48 Done.
82 }
83 [button setEnabled:enabled];
84 }
85
86 // Init the enabled state of the buttons on the toolbar to match the state in
87 // the controller.
88 - (void)initCommandStatus:(CommandUpdater*)commands {
89 [backButton_ setEnabled:commands->IsCommandEnabled(IDC_BACK) ? YES : NO];
90 [forwardButton_
91 setEnabled:commands->IsCommandEnabled(IDC_FORWARD) ? YES : NO];
92 [reloadButton_
93 setEnabled:commands->IsCommandEnabled(IDC_RELOAD) ? YES : NO];
94 [starButton_ setEnabled:commands->IsCommandEnabled(IDC_STAR) ? YES : NO];
TVL 2009/04/09 15:53:00 todo(pinkerton) home button
pink (ping after 24hrs) 2009/04/09 16:00:48 Done.
95 }
96
97 - (void)updateToolbarWithContents:(TabContents*)tab {
98 // TODO(pinkerton): there's a lot of ui code in autocomplete_edit.cc
99 // that we'll want to duplicate. For now, just handle setting the text.
100
101 // TODO(pinkerton): update the security lock icon and background color
102
103 NSString* urlString = base::SysWideToNSString(toolbarModel_->GetText());
104 [locationBar_ setStringValue:urlString];
105 }
106
107 - (void)setStarredState:(BOOL)isStarred {
108 NSString* starImageName = kStarImageName;
109 if (isStarred)
110 starImageName = kStarredImageName;
111 [starButton_ setImage:[NSImage imageNamed:starImageName]];
112 }
113
114 - (void)setIsLoading:(BOOL)isLoading {
115 NSString* imageName = @"go";
116 if (isLoading)
117 imageName = @"stop";
118 [goButton_ setImage:[NSImage imageNamed:imageName]];
119 }
120
121 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698