Add context menus to tabs.

BUG=14920
TEST=context menus on tabs.
Review URL: http://codereview.chromium.org/155173

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20155 0039d316-1c4b-4281-b951-d872f2087c98
parent 13367f79
This diff is collapsed.
...@@ -34,8 +34,9 @@ enum TabLoadingState { ...@@ -34,8 +34,9 @@ enum TabLoadingState {
@interface TabController : NSViewController { @interface TabController : NSViewController {
@private @private
IBOutlet NSButton *backgroundButton_; IBOutlet NSButton* backgroundButton_;
IBOutlet NSView* iconView_; IBOutlet NSView* iconView_;
IBOutlet NSMenu* contextMenu_;
BOOL selected_; BOOL selected_;
TabLoadingState loadingState_; TabLoadingState loadingState_;
id<TabControllerTarget> target_; // weak, where actions are sent id<TabControllerTarget> target_; // weak, where actions are sent
...@@ -59,6 +60,9 @@ enum TabLoadingState { ...@@ -59,6 +60,9 @@ enum TabLoadingState {
// perform the close. // perform the close.
- (IBAction)closeTab:(id)sender; - (IBAction)closeTab:(id)sender;
// Dispatches the command in the tag to the registered target object.
- (IBAction)commandDispatch:(id)sender;
// Replace the current icon view with the given view. |iconView| will be // Replace the current icon view with the given view. |iconView| will be
// resized to the size of the current icon view. // resized to the size of the current icon view.
- (void)setIconView:(NSView*)iconView; - (void)setIconView:(NSView*)iconView;
......
...@@ -55,6 +55,22 @@ ...@@ -55,6 +55,22 @@
} }
} }
// Dispatches the command in the tag to the registered target object.
- (IBAction)commandDispatch:(id)sender {
TabStripModel::ContextMenuCommand command =
static_cast<TabStripModel::ContextMenuCommand>([sender tag]);
[[self target] commandDispatch:command forController:self];
}
// Called for each menu item on its target, which would be this controller.
// Returns YES if the menu item should be enabled. We ask the tab's
// target for the proper answer.
- (BOOL)validateMenuItem:(NSMenuItem*)item {
TabStripModel::ContextMenuCommand command =
static_cast<TabStripModel::ContextMenuCommand>([item tag]);
return [[self target] isCommandEnabled:command forController:self];
}
- (void)setTitle:(NSString *)title { - (void)setTitle:(NSString *)title {
[backgroundButton_ setToolTip:title]; [backgroundButton_ setToolTip:title];
[super setTitle:title]; [super setTitle:title];
......
...@@ -5,10 +5,22 @@ ...@@ -5,10 +5,22 @@
#ifndef CHROME_BROWSER_COCOA_TAB_CONTROLLER_TARGET_H_ #ifndef CHROME_BROWSER_COCOA_TAB_CONTROLLER_TARGET_H_
#define CHROME_BROWSER_COCOA_TAB_CONTROLLER_TARGET_H_ #define CHROME_BROWSER_COCOA_TAB_CONTROLLER_TARGET_H_
#include "chrome/browser/tabs/tab_strip_model.h"
@class TabController;
// A protocol to be implemented by a TabController's target. // A protocol to be implemented by a TabController's target.
@protocol TabControllerTarget @protocol TabControllerTarget
- (void)selectTab:(id)sender; - (void)selectTab:(id)sender;
- (void)closeTab:(id)sender; - (void)closeTab:(id)sender;
// Dispatch context menu commands for the given tab controller.
- (void)commandDispatch:(TabStripModel::ContextMenuCommand)command
forController:(TabController*)controller;
// Returns YES if the specificed command should be enabled for the given
// controller.
- (BOOL)isCommandEnabled:(TabStripModel::ContextMenuCommand)command
forController:(TabController*)controller;
@end @end
#endif // CHROME_BROWSER_COCOA_TAB_CONTROLLER_TARGET_H_ #endif // CHROME_BROWSER_COCOA_TAB_CONTROLLER_TARGET_H_
...@@ -166,6 +166,21 @@ NSString* const kTabStripNumberOfTabsChanged = @"kTabStripNumberOfTabsChanged"; ...@@ -166,6 +166,21 @@ NSString* const kTabStripNumberOfTabsChanged = @"kTabStripNumberOfTabsChanged";
} }
} }
// Dispatch context menu commands for the given tab controller.
- (void)commandDispatch:(TabStripModel::ContextMenuCommand)command
forController:(TabController*)controller {
int index = [self indexForTabView:[controller view]];
tabModel_->ExecuteContextMenuCommand(index, command);
}
// Returns YES if the specificed command should be enabled for the given
// controller.
- (BOOL)isCommandEnabled:(TabStripModel::ContextMenuCommand)command
forController:(TabController*)controller {
int index = [self indexForTabView:[controller view]];
return tabModel_->IsContextMenuCommandEnabled(index, command) ? YES : NO;
}
- (void)insertPlaceholderForTab:(TabView*)tab - (void)insertPlaceholderForTab:(TabView*)tab
frame:(NSRect)frame frame:(NSRect)frame
yStretchiness:(CGFloat)yStretchiness { yStretchiness:(CGFloat)yStretchiness {
......
...@@ -254,7 +254,7 @@ static const double kDragStartDistance = 3.0; ...@@ -254,7 +254,7 @@ static const double kDragStartDistance = 3.0;
NSPoint origin = sourceWindowFrame_.origin; NSPoint origin = sourceWindowFrame_.origin;
origin.x += (thisPoint.x - dragOrigin_.x); origin.x += (thisPoint.x - dragOrigin_.x);
origin.y += (thisPoint.y - dragOrigin_.y); origin.y += (thisPoint.y - dragOrigin_.y);
if (tearProgress < 1) { if (tearProgress < 1) {
// If the tear animation is not complete, call back to ourself with the // If the tear animation is not complete, call back to ourself with the
// same event to animate even if the mouse isn't moving. // same event to animate even if the mouse isn't moving.
...@@ -262,7 +262,7 @@ static const double kDragStartDistance = 3.0; ...@@ -262,7 +262,7 @@ static const double kDragStartDistance = 3.0;
[self performSelector:@selector(mouseDragged:) [self performSelector:@selector(mouseDragged:)
withObject:theEvent withObject:theEvent
afterDelay:1.0f/30.0f]; afterDelay:1.0f/30.0f];
origin.x = (1 - tearProgress) * tearOrigin_.x + tearProgress * origin.x; origin.x = (1 - tearProgress) * tearOrigin_.x + tearProgress * origin.x;
origin.y = (1 - tearProgress) * tearOrigin_.y + tearProgress * origin.y; origin.y = (1 - tearProgress) * tearOrigin_.y + tearProgress * origin.y;
} }
...@@ -355,11 +355,17 @@ static const double kDragStartDistance = 3.0; ...@@ -355,11 +355,17 @@ static const double kDragStartDistance = 3.0;
[sourceController_ removePlaceholder]; [sourceController_ removePlaceholder];
} }
- (void)otherMouseUp:(NSEvent*) theEvent { - (void)otherMouseUp:(NSEvent*)theEvent {
// Support middle-click-to-close. // Support middle-click-to-close.
if ([theEvent buttonNumber] == 2) { if ([theEvent buttonNumber] == 2) {
[controller_ closeTab:self]; [controller_ closeTab:self];
} }
} }
// Called when the user hits the right mouse button (or control-clicks) to
// show a context menu.
- (void)rightMouseDown:(NSEvent*)theEvent {
[NSMenu popUpContextMenu:[self menu] withEvent:theEvent forView:self];
}
@end @end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment