summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/app_controller_mac.h5
-rw-r--r--chrome/browser/app_controller_mac.mm54
-rw-r--r--chrome/browser/browser.cc16
-rw-r--r--chrome/browser/browser.h7
-rw-r--r--chrome/browser/browser_window_controller.h3
-rw-r--r--chrome/browser/browser_window_controller.mm30
6 files changed, 110 insertions, 5 deletions
diff --git a/chrome/browser/app_controller_mac.h b/chrome/browser/app_controller_mac.h
index 09fa014..db562a3 100644
--- a/chrome/browser/app_controller_mac.h
+++ b/chrome/browser/app_controller_mac.h
@@ -7,11 +7,14 @@
#import <Cocoa/Cocoa.h>
+class CommandUpdater;
+
// The application controller object, created by loading the MainMenu nib.
// This handles things like responding to menus when there are no windows
// open, etc and acts as the NSApplication delegate.
-@interface AppController : NSObject {
+@interface AppController : NSObject<NSUserInterfaceValidations> {
@public
+ CommandUpdater* menuState_; // strong ref
}
- (IBAction)quit:(id)sender;
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm
index 16073d8..f2face3 100644
--- a/chrome/browser/app_controller_mac.mm
+++ b/chrome/browser/app_controller_mac.mm
@@ -5,10 +5,27 @@
#import "app_controller_mac.h"
#import "base/message_loop.h"
+#import "chrome/app/chrome_dll_resource.h"
+#import "chrome/browser/browser.h"
#import "chrome/browser/browser_list.h"
+#import "chrome/browser/command_updater.h"
+
+@interface AppController(PRIVATE)
+- (void)initMenuState;
+@end
@implementation AppController
+- (void)awakeFromNib {
+ // set up the command updater for when there are no windows open
+ [self initMenuState];
+}
+
+- (void)dealloc {
+ delete menuState_;
+ [super dealloc];
+}
+
// We can't use the standard terminate: method because it will abrubptly exit
// the app and leave things on the stack in an unfinalized state. We need to
// post a quit message to our run loop so the stack can gracefully unwind.
@@ -32,5 +49,42 @@
MessageLoopForUI::current()->Quit();
}
+// Called to validate menu items when there are no key windows. All the
+// items we care about have been set with the |commandDispatch:| action and
+// a target of FirstResponder in IB. If it's not one of those, let it
+// continue up the responder chain to be handled elsewhere. We pull out the
+// tag as the cross-platform constant to differentiate and dispatch the
+// various commands.
+- (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item {
+ SEL action = [item action];
+ BOOL enable = NO;
+ if (action == @selector(commandDispatch:)) {
+ NSInteger tag = [item tag];
+ if (menuState_->SupportsCommand(tag))
+ enable = menuState_->IsCommandEnabled(tag) ? YES : NO;
+ } else if (action == @selector(quit:)) {
+ enable = YES;
+ }
+ return enable;
+}
+
+// Called when the user picks a menu item when there are no key windows. Calls
+// through to the browser object to execute the command. This assumes that the
+// command is supported and doesn't check, otherwise it would have been disabled
+// in the UI in validateUserInterfaceItem:.
+- (void)commandDispatch:(id)sender {
+ NSInteger tag = [sender tag];
+ switch (tag) {
+ case IDC_NEW_WINDOW:
+ Browser::OpenEmptyWindow(NULL);
+ break;
+ };
+}
+
+- (void)initMenuState {
+ menuState_ = new CommandUpdater(NULL);
+ menuState_->UpdateCommandEnabled(IDC_NEW_WINDOW, true);
+ // TODO(pinkerton): ...more to come...
+}
@end
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index ddceec2..6691066 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -6,6 +6,7 @@
#include "base/idle_timer.h"
#include "base/logging.h"
#include "base/string_util.h"
+#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/browser_list.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
@@ -22,7 +23,6 @@
#include "chrome/browser/browser.h"
-#include "chrome/app/chrome_dll_resource.h"
#include "chrome/app/locales/locale_settings.h"
#include "chrome/browser/automation/ui_controls.h"
#include "chrome/browser/browser_process.h"
@@ -1070,6 +1070,8 @@ Browser* Browser::GetBrowserForController(
return NULL;
}
+#endif // OS_WIN
+
///////////////////////////////////////////////////////////////////////////////
// Browser, CommandUpdater::CommandUpdaterDelegate implementation:
@@ -1089,6 +1091,7 @@ void Browser::ExecuteCommand(int id) {
// The order of commands in this switch statement must match the function
// declaration order in browser.h!
switch (id) {
+#if defined(OS_WIN)
// Navigation commands
case IDC_BACK: GoBack(); break;
case IDC_FORWARD: GoForward(); break;
@@ -1217,12 +1220,17 @@ void Browser::ExecuteCommand(int id) {
case IDC_ABOUT: OpenAboutChromeDialog(); break;
case IDC_HELP_PAGE: OpenHelpTab(); break;
+#elif defined(OS_MACOSX)
+ case IDC_NEW_WINDOW: NewWindow(); break;
+#endif
default:
LOG(WARNING) << "Received Unimplemented Command: " << id;
break;
}
}
+#if defined(OS_WIN)
+
///////////////////////////////////////////////////////////////////////////////
// Browser, TabStripModelDelegate implementation:
@@ -1884,6 +1892,8 @@ void Browser::Observe(NotificationType type,
}
}
+#endif // OS_WIN
+
///////////////////////////////////////////////////////////////////////////////
// Browser, Command and state updating (private):
@@ -2005,9 +2015,11 @@ void Browser::InitCommandState() {
// Show various bits of UI
command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, normal_window);
+#if defined(OS_WIN)
command_updater_.UpdateCommandEnabled(IDC_DEBUGGER,
// The debugger doesn't work in single process mode.
normal_window && !RenderProcessHost::run_renderer_in_process());
+#endif
command_updater_.UpdateCommandEnabled(IDC_NEW_PROFILE, normal_window);
command_updater_.UpdateCommandEnabled(IDC_REPORT_BUG, normal_window);
command_updater_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_BAR, normal_window);
@@ -2022,6 +2034,8 @@ void Browser::InitCommandState() {
}
}
+#if defined(OS_WIN)
+
void Browser::UpdateCommandsForTabState() {
TabContents* current_tab = GetSelectedTabContents();
if (!current_tab) // May be NULL during tab restore.
diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h
index 3157e5a..cd53a18 100644
--- a/chrome/browser/browser.h
+++ b/chrome/browser/browser.h
@@ -16,6 +16,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_window.h"
+#include "chrome/browser/command_updater.h"
#include "chrome/browser/sessions/session_id.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/pref_member.h"
@@ -23,7 +24,6 @@
#include "skia/include/SkBitmap.h"
#if defined(OS_WIN)
-#include "chrome/browser/command_updater.h"
#include "chrome/browser/shell_dialogs.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tab_contents/tab_contents_delegate.h"
@@ -238,9 +238,10 @@ class Browser : public TabStripModelDelegate,
void OpenCurrentURL();
void Go();
void Stop();
-
+#endif
// Window management commands
void NewWindow();
+#if defined(OS_WIN)
void NewIncognitoWindow();
void NewProfileWindowByIndex(int index);
void CloseWindow();
@@ -320,10 +321,12 @@ class Browser : public TabStripModelDelegate,
const NavigationController* controller, int* index);
// Interface implementations ////////////////////////////////////////////////
+#endif
// Overridden from CommandUpdater::CommandUpdaterDelegate:
virtual void ExecuteCommand(int id);
+#if defined(OS_WIN)
// Overridden from TabStripModelDelegate:
virtual GURL GetBlankTabURL() const;
virtual void CreateNewStripWithContents(TabContents* detached_contents,
diff --git a/chrome/browser/browser_window_controller.h b/chrome/browser/browser_window_controller.h
index 7ae2bd0..9d99a2e 100644
--- a/chrome/browser/browser_window_controller.h
+++ b/chrome/browser/browser_window_controller.h
@@ -13,7 +13,8 @@
class Browser;
class BrowserWindow;
-@interface BrowserWindowController : NSWindowController {
+@interface BrowserWindowController :
+ NSWindowController<NSUserInterfaceValidations> {
@private
Browser* browser_; // strong
BrowserWindow* window_shim_; // strong
diff --git a/chrome/browser/browser_window_controller.mm b/chrome/browser/browser_window_controller.mm
index c5e4abc..bb5b9cc 100644
--- a/chrome/browser/browser_window_controller.mm
+++ b/chrome/browser/browser_window_controller.mm
@@ -58,6 +58,36 @@
return YES;
}
+// Called to validate menu and toolbar items when this window is key. All the
+// items we care about have been set with the |commandDispatch:| action and
+// a target of FirstResponder in IB. If it's not one of those, let it
+// continue up the responder chain to be handled elsewhere. We pull out the
+// tag as the cross-platform constant to differentiate and dispatch the
+// various commands.
+// NOTE: we might have to handle state for app-wide menu items,
+// although we could cheat and directly ask the app controller if our
+// command_updater doesn't support the command. This may or may not be an issue,
+// too early to tell.
+- (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item {
+ SEL action = [item action];
+ BOOL enable = NO;
+ if (action == @selector(commandDispatch:)) {
+ NSInteger tag = [item tag];
+ if (browser_->command_updater()->SupportsCommand(tag))
+ enable = browser_->command_updater()->IsCommandEnabled(tag) ? YES : NO;
+ }
+ return enable;
+}
+
+// Called when the user picks a menu or toolbar item when this window is key.
+// Calls through to the browser object to execute the command. This assumes that
+// the command is supported and doesn't check, otherwise it would have been
+// disabled in the UI in validateUserInterfaceItem:.
+- (void)commandDispatch:(id)sender {
+ NSInteger tag = [sender tag];
+ browser_->ExecuteCommand(tag);
+}
+
// NSToolbar delegate methods
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar {