summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/app/nibs/English.lproj/TabContents.xib57
-rw-r--r--chrome/browser/browser.cc8
-rw-r--r--chrome/browser/browser.h4
-rw-r--r--chrome/browser/browser_window_controller.mm4
-rw-r--r--chrome/browser/cocoa/tab_contents_controller.h21
-rw-r--r--chrome/browser/cocoa/tab_contents_controller.mm98
-rw-r--r--chrome/browser/cocoa/tab_strip_controller.h12
-rw-r--r--chrome/browser/cocoa/tab_strip_controller.mm11
-rw-r--r--chrome/common/temp_scaffolding_stubs.h2
9 files changed, 199 insertions, 18 deletions
diff --git a/chrome/app/nibs/English.lproj/TabContents.xib b/chrome/app/nibs/English.lproj/TabContents.xib
index 97b9ae0..5c8f89e 100644
--- a/chrome/app/nibs/English.lproj/TabContents.xib
+++ b/chrome/app/nibs/English.lproj/TabContents.xib
@@ -413,6 +413,38 @@
</object>
<int key="connectionID">163</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">backButton_</string>
+ <reference key="source" ref="326691890"/>
+ <reference key="destination" ref="213122875"/>
+ </object>
+ <int key="connectionID">165</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">forwardButton_</string>
+ <reference key="source" ref="326691890"/>
+ <reference key="destination" ref="131791940"/>
+ </object>
+ <int key="connectionID">166</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">reloadStopButton_</string>
+ <reference key="source" ref="326691890"/>
+ <reference key="destination" ref="1046981093"/>
+ </object>
+ <int key="connectionID">167</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">starButton_</string>
+ <reference key="source" ref="326691890"/>
+ <reference key="destination" ref="574811940"/>
+ </object>
+ <int key="connectionID">168</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -654,9 +686,9 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{376, 138}, {480, 360}}</string>
+ <string>{{523, 153}, {480, 360}}</string>
<boolean value="YES" id="5"/>
- <string>{{376, 138}, {480, 360}}</string>
+ <string>{{523, 153}, {480, 360}}</string>
<reference ref="5"/>
<reference ref="5"/>
<string>{480, 360}</string>
@@ -684,7 +716,7 @@
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">164</int>
+ <int key="maxID">168</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -709,8 +741,23 @@
<string key="NS.object.0">id</string>
</object>
<object class="NSMutableDictionary" key="outlets">
- <string key="NS.key.0">locationBar_</string>
- <string key="NS.object.0">NSTextField</string>
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSMutableArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>backButton_</string>
+ <string>forwardButton_</string>
+ <string>locationBar_</string>
+ <string>reloadStopButton_</string>
+ <string>starButton_</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>NSButton</string>
+ <string>NSButton</string>
+ <string>NSTextField</string>
+ <string>NSButton</string>
+ <string>NSButton</string>
+ </object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index a79c5b5..e9c48f1 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -1446,6 +1446,8 @@ void Browser::TabDetachedAt(TabContents* contents, int index) {
Source<TabContents>(contents));
}
+#endif
+
void Browser::TabSelectedAt(TabContents* old_contents,
TabContents* new_contents,
int index,
@@ -1512,6 +1514,8 @@ void Browser::TabStripEmpty() {
method_factory_.NewRunnableMethod(&Browser::CloseFrame));
}
+#if defined(OS_WIN)
+
///////////////////////////////////////////////////////////////////////////////
// Browser, TabContentsDelegate implementation:
@@ -2420,12 +2424,12 @@ void Browser::AdvanceFindSelection(bool forward_direction) {
*this, true, forward_direction);
}
+#endif // OS_WIN
+
void Browser::CloseFrame() {
window_->Close();
}
-#endif // OS_WIN
-
// static
std::wstring Browser::ComputeApplicationNameFromURL(const GURL& url) {
std::string t;
diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h
index 36fb097..1874426 100644
--- a/chrome/browser/browser.h
+++ b/chrome/browser/browser.h
@@ -348,6 +348,7 @@ class Browser : public TabStripModelDelegate,
bool foreground);
virtual void TabClosingAt(TabContents* contents, int index);
virtual void TabDetachedAt(TabContents* contents, int index);
+#endif
virtual void TabSelectedAt(TabContents* old_contents,
TabContents* new_contents,
int index,
@@ -357,6 +358,7 @@ class Browser : public TabStripModelDelegate,
int to_index);
virtual void TabStripEmpty();
+#if defined(OS_WIN)
// Overridden from TabContentsDelegate:
virtual void OpenURLFromTab(TabContents* source,
const GURL& url, const GURL& referrer,
@@ -517,13 +519,13 @@ class Browser : public TabStripModelDelegate,
// Advance the find selection by one. Direction is either forward or
// backwards depending on parameter passed in.
void AdvanceFindSelection(bool forward_direction);
+#endif
// Closes the frame.
// TODO(beng): figure out if we need this now that the frame itself closes
// after a return to the message loop.
void CloseFrame();
-#endif // OS_WIN
// Compute a deterministic name based on the URL. We use this pseudo name
// as a key to store window location per application URLs.
diff --git a/chrome/browser/browser_window_controller.mm b/chrome/browser/browser_window_controller.mm
index a4d546d..dce4c3b 100644
--- a/chrome/browser/browser_window_controller.mm
+++ b/chrome/browser/browser_window_controller.mm
@@ -43,7 +43,9 @@
// managing the creation of new tabs.
tabStripController_ =
[[TabStripController alloc]
- initWithView:tabStripView_ model:browser_->tabstrip_model()];
+ initWithView:tabStripView_
+ model:browser_->tabstrip_model()
+ commands:browser_->command_updater()];
// Place the tab bar above the content box and add it to the view hierarchy
// as a sibling of the content view so it can overlap with the window frame.
diff --git a/chrome/browser/cocoa/tab_contents_controller.h b/chrome/browser/cocoa/tab_contents_controller.h
index 903b020..d2cee1f 100644
--- a/chrome/browser/cocoa/tab_contents_controller.h
+++ b/chrome/browser/cocoa/tab_contents_controller.h
@@ -7,6 +7,11 @@
#include <Cocoa/Cocoa.h>
+class CommandUpdater;
+class TabContents;
+class TabContentsCommandObserver;
+class TabStripModel;
+
// A class that controls the contents of a tab, including the toolbar and
// web area.
@@ -20,10 +25,24 @@
@interface TabContentsController : NSViewController {
@private
+ CommandUpdater* commands_; // weak, may be nil
+ TabContentsCommandObserver* observer_; // nil if |commands_| is nil
+ IBOutlet NSButton* backButton_;
+ IBOutlet NSButton* forwardButton_;
+ IBOutlet NSButton* reloadStopButton_;
+ IBOutlet NSButton* starButton_;
IBOutlet NSTextField* locationBar_;
}
-// take this view (toolbar and web contents) full screen
+// Create the contents of a tab represented by |contents| and loaded from the
+// nib given by |name|. |commands| allows tracking of what's enabled and
+// disabled. It may be nil if no updating is desired.
+- (id)initWithNibName:(NSString*)name
+ bundle:(NSBundle*)bundle
+ contents:(TabContents*)contents
+ commands:(CommandUpdater*)commands;
+
+// Take this view (toolbar and web contents) full screen
- (IBAction)fullScreen:(id)sender;
@end
diff --git a/chrome/browser/cocoa/tab_contents_controller.mm b/chrome/browser/cocoa/tab_contents_controller.mm
index 5ef5a4d..f31047a 100644
--- a/chrome/browser/cocoa/tab_contents_controller.mm
+++ b/chrome/browser/cocoa/tab_contents_controller.mm
@@ -4,11 +4,40 @@
#include "chrome/browser/cocoa/tab_contents_controller.h"
+#import "chrome/app/chrome_dll_resource.h"
+#import "chrome/browser/command_updater.h"
+
+@interface TabContentsController(CommandUpdates)
+- (void)enabledStateChangedForCommand:(NSInteger)command enabled:(BOOL)enabled;
+@end
+
+// A C++ bridge class that handles listening for updates to commands and
+// passing them back to the controller.
+class TabContentsCommandObserver : public CommandUpdater::CommandObserver {
+ public:
+ TabContentsCommandObserver(TabContentsController* controller,
+ CommandUpdater* commands);
+ ~TabContentsCommandObserver();
+
+ // Overridden from CommandUpdater::CommandObserver
+ void EnabledStateChangedForCommand(int command, bool enabled);
+
+ private:
+ TabContentsController* controller_; // weak, owns us
+ CommandUpdater* commands_; // weak
+};
+
+
@implementation TabContentsController
-- (id)initWithNibName:(NSString*)name bundle:(NSBundle*)bundle {
+- (id)initWithNibName:(NSString*)name
+ bundle:(NSBundle*)bundle
+ contents:(TabContents*)contents
+ commands:(CommandUpdater*)commands {
if ((self = [super initWithNibName:name bundle:bundle])) {
- // nothing to do
+ commands_ = commands;
+ if (commands_)
+ observer_ = new TabContentsCommandObserver(self, commands);
}
return self;
}
@@ -16,6 +45,7 @@
- (void)dealloc {
// make sure our contents have been removed from the window
[[self view] removeFromSuperview];
+ delete observer_;
[super dealloc];
}
@@ -23,6 +53,41 @@
[locationBar_ setStringValue:@"http://dev.chromium.org"];
}
+// Returns YES if the tab represented by this controller is the front-most.
+- (BOOL)isCurrentTab {
+ // We're the current tab if we're in the view hierarchy, otherwise some other
+ // tab is.
+ return [[self view] superview] ? YES : NO;
+}
+
+// Called when the state for a command changes to |enabled|. Update the
+// corresponding UI element.
+- (void)enabledStateChangedForCommand:(NSInteger)command enabled:(BOOL)enabled {
+ // We don't need to update anything if we're not the frontmost tab.
+ // TODO(pinkerton): i'm worried that observer ordering could cause the
+ // notification to be sent before we've been put into the view, but we
+ // appear to be called in the right order so far.
+ if (![self isCurrentTab])
+ return;
+
+ 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];
+}
+
- (IBAction)fullScreen:(id)sender {
if ([[self view] isInFullScreenMode]) {
[[self view] exitFullScreenModeWithOptions:nil];
@@ -32,3 +97,32 @@
}
@end
+
+//--------------------------------------------------------------------------
+
+TabContentsCommandObserver::TabContentsCommandObserver(
+ TabContentsController* controller, CommandUpdater* commands)
+ : controller_(controller), commands_(commands) {
+ DCHECK(controller_ && commands);
+ // Register for notifications about state changes for the toolbar buttons
+ commands_->AddCommandObserver(IDC_BACK, this);
+ commands_->AddCommandObserver(IDC_FORWARD, this);
+ commands_->AddCommandObserver(IDC_RELOAD, this);
+ commands_->AddCommandObserver(IDC_HOME, this);
+ commands_->AddCommandObserver(IDC_STAR, this);
+}
+
+TabContentsCommandObserver::~TabContentsCommandObserver() {
+ // Unregister the notifications
+ commands_->RemoveCommandObserver(IDC_BACK, this);
+ commands_->RemoveCommandObserver(IDC_FORWARD, this);
+ commands_->RemoveCommandObserver(IDC_RELOAD, this);
+ commands_->RemoveCommandObserver(IDC_HOME, this);
+ commands_->RemoveCommandObserver(IDC_STAR, this);
+}
+
+void TabContentsCommandObserver::EnabledStateChangedForCommand(int command,
+ bool enabled) {
+ [controller_ enabledStateChangedForCommand:command
+ enabled:enabled ? YES : NO];
+}
diff --git a/chrome/browser/cocoa/tab_strip_controller.h b/chrome/browser/cocoa/tab_strip_controller.h
index f1a4eb4..2330bd5 100644
--- a/chrome/browser/cocoa/tab_strip_controller.h
+++ b/chrome/browser/cocoa/tab_strip_controller.h
@@ -7,6 +7,7 @@
#import <Cocoa/Cocoa.h>
+class CommandUpdater;
@class TabStripView;
class TabStripBridge;
class TabStripModel;
@@ -26,14 +27,19 @@ class TabStripModel;
TabStripView* tabView_; // weak
NSButton* newTabButton_;
TabStripBridge* bridge_;
- TabStripModel* model_;
+ TabStripModel* model_; // weak
+ CommandUpdater* commands_; // weak, may be nil
// maps TabContents to a TabContentsController (which owns the parent view
// for the toolbar and associated tab contents)
NSMutableDictionary* tabContentsToController_;
}
-// Initialize the controller with a view and model. Both must be non-nil.
-- (id)initWithView:(TabStripView*)view model:(TabStripModel*)model;
+// Initialize the controller with a view, model, and command updater for
+// tracking what's enabled and disabled. |commands| may be nil if no updating
+// is desired.
+- (id)initWithView:(TabStripView*)view
+ model:(TabStripModel*)model
+ commands:(CommandUpdater*)commands;
@end
diff --git a/chrome/browser/cocoa/tab_strip_controller.mm b/chrome/browser/cocoa/tab_strip_controller.mm
index d21a64c..2ba72e2 100644
--- a/chrome/browser/cocoa/tab_strip_controller.mm
+++ b/chrome/browser/cocoa/tab_strip_controller.mm
@@ -56,11 +56,14 @@ class TabStripBridge : public TabStripModelObserver {
@implementation TabStripController
-- (id)initWithView:(TabStripView*)view model:(TabStripModel*)model {
+- (id)initWithView:(TabStripView*)view
+ model:(TabStripModel*)model
+ commands:(CommandUpdater*)commands {
DCHECK(view && model);
if ((self = [super init])) {
tabView_ = view;
model_ = model;
+ commands_ = commands;
bridge_ = new TabStripBridge(model, self);
tabContentsToController_ = [[NSMutableDictionary alloc] init];
@@ -193,8 +196,10 @@ class TabStripBridge : public TabStripModelObserver {
// TODO(pinkerton): will eventually need to pass |contents| to the
// controller to complete hooking things up.
TabContentsController* contentsController =
- [[[TabContentsController alloc] initWithNibName:@"TabContents" bundle:nil]
- autorelease];
+ [[[TabContentsController alloc] initWithNibName:@"TabContents"
+ bundle:nil
+ contents:contents
+ commands:commands_] autorelease];
NSValue* key = [NSValue valueWithPointer:contents];
[tabContentsToController_ setObject:contentsController forKey:key];
diff --git a/chrome/common/temp_scaffolding_stubs.h b/chrome/common/temp_scaffolding_stubs.h
index bd6dcbc..19f5b4a 100644
--- a/chrome/common/temp_scaffolding_stubs.h
+++ b/chrome/common/temp_scaffolding_stubs.h
@@ -175,6 +175,7 @@ class SessionService : public base::RefCountedThreadSafe<SessionService> {
void WindowClosing(const SessionID&) { NOTIMPLEMENTED(); }
void SetTabIndexInWindow(const SessionID&, const SessionID&, int)
{ NOTIMPLEMENTED(); }
+ void SetSelectedTabInWindow(const SessionID&, int) { NOTIMPLEMENTED(); }
};
class SessionRestore {
@@ -498,6 +499,7 @@ class AcceleratorHandler {
class StatusBubble {
public:
void SetStatus(const std::wstring&) { NOTIMPLEMENTED(); }
+ void Hide() { NOTIMPLEMENTED(); }
};
class SavePackage : public base::RefCountedThreadSafe<SavePackage>,