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

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

Issue 1725006: Changes the tab menu to use pin and unpin instead of a check. The mac (Closed)
Patch Set: Merged with tip of tree and updated unit tests Created 10 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
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/gtk/tabs/tab_gtk.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "app/l10n_util_mac.h" 5 #include "app/l10n_util_mac.h"
6 #include "base/mac_util.h" 6 #include "base/mac_util.h"
7 #import "chrome/browser/browser_theme_provider.h" 7 #import "chrome/browser/browser_theme_provider.h"
8 #import "chrome/browser/cocoa/menu_controller.h" 8 #import "chrome/browser/cocoa/menu_controller.h"
9 #import "chrome/browser/cocoa/tab_controller.h" 9 #import "chrome/browser/cocoa/tab_controller.h"
10 #import "chrome/browser/cocoa/tab_controller_target.h" 10 #import "chrome/browser/cocoa/tab_controller_target.h"
(...skipping 10 matching lines...) Expand all
21 @synthesize action = action_; 21 @synthesize action = action_;
22 22
23 namespace TabControllerInternal { 23 namespace TabControllerInternal {
24 24
25 // A C++ delegate that handles enabling/disabling menu items and handling when 25 // A C++ delegate that handles enabling/disabling menu items and handling when
26 // a menu command is chosen. Also fixes up the menu item label for "pin/unpin 26 // a menu command is chosen. Also fixes up the menu item label for "pin/unpin
27 // tab". 27 // tab".
28 class MenuDelegate : public menus::SimpleMenuModel::Delegate { 28 class MenuDelegate : public menus::SimpleMenuModel::Delegate {
29 public: 29 public:
30 explicit MenuDelegate(id<TabControllerTarget> target, TabController* owner) 30 explicit MenuDelegate(id<TabControllerTarget> target, TabController* owner)
31 : target_(target), owner_(owner) { } 31 : target_(target),
32 owner_(owner) {}
32 33
33 // Overridden from menus::SimpleMenuModel::Delegate 34 // Overridden from menus::SimpleMenuModel::Delegate
34 virtual bool IsCommandIdChecked(int command_id) const { return false; } 35 virtual bool IsCommandIdChecked(int command_id) const { return false; }
35 virtual bool IsCommandIdEnabled(int command_id) const { 36 virtual bool IsCommandIdEnabled(int command_id) const {
36 TabStripModel::ContextMenuCommand command = 37 TabStripModel::ContextMenuCommand command =
37 static_cast<TabStripModel::ContextMenuCommand>(command_id); 38 static_cast<TabStripModel::ContextMenuCommand>(command_id);
38 return [target_ isCommandEnabled:command forController:owner_]; 39 return [target_ isCommandEnabled:command forController:owner_];
39 } 40 }
40 virtual bool GetAcceleratorForCommandId( 41 virtual bool GetAcceleratorForCommandId(
41 int command_id, 42 int command_id,
42 menus::Accelerator* accelerator) { return false; } 43 menus::Accelerator* accelerator) { return false; }
43 virtual void ExecuteCommand(int command_id) { 44 virtual void ExecuteCommand(int command_id) {
44 TabStripModel::ContextMenuCommand command = 45 TabStripModel::ContextMenuCommand command =
45 static_cast<TabStripModel::ContextMenuCommand>(command_id); 46 static_cast<TabStripModel::ContextMenuCommand>(command_id);
46 [target_ commandDispatch:command forController:owner_]; 47 [target_ commandDispatch:command forController:owner_];
47 } 48 }
48 49
49 virtual bool IsLabelForCommandIdDynamic(int command_id) const {
50 return command_id == TabStripModel::CommandTogglePinned;
51 }
52 virtual string16 GetLabelForCommandId(int command_id) const {
53 // Display "Pin Tab" when the tab is not pinned and "Unpin Tab" when it is
54 // (this is not a checkmark menu item, per Apple's HIG).
55 if (command_id == TabStripModel::CommandTogglePinned) {
56 return l10n_util::GetStringUTF16(
57 [owner_ mini] ? IDS_TAB_CXMENU_UNPIN_TAB_MAC
58 : IDS_TAB_CXMENU_PIN_TAB_MAC);
59 }
60 return string16();
61 }
62
63 private: 50 private:
64 id<TabControllerTarget> target_; // weak 51 id<TabControllerTarget> target_; // weak
65 TabController* owner_; // weak, owns me 52 TabController* owner_; // weak, owns me
66 }; 53 };
67 54
68 } // TabControllerInternal namespace 55 } // TabControllerInternal namespace
69 56
70 // The min widths match the windows values and are sums of left + right 57 // The min widths match the windows values and are sums of left + right
71 // padding, of which we have no comparable constants (we draw using paths, not 58 // padding, of which we have no comparable constants (we draw using paths, not
72 // images). The selected tab width includes the close button width. 59 // images). The selected tab width includes the close button width.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 118
132 [self internalSetSelected:selected_]; 119 [self internalSetSelected:selected_];
133 } 120 }
134 121
135 // Called when Cocoa wants to display the context menu. Lazily instantiate 122 // Called when Cocoa wants to display the context menu. Lazily instantiate
136 // the menu based off of the cross-platform model. Re-create the menu and 123 // the menu based off of the cross-platform model. Re-create the menu and
137 // model every time to get the correct labels and enabling. 124 // model every time to get the correct labels and enabling.
138 - (NSMenu*)menu { 125 - (NSMenu*)menu {
139 contextMenuDelegate_.reset( 126 contextMenuDelegate_.reset(
140 new TabControllerInternal::MenuDelegate(target_, self)); 127 new TabControllerInternal::MenuDelegate(target_, self));
141 contextMenuModel_.reset(new TabMenuModel(contextMenuDelegate_.get())); 128 // TODO(42339): this is wrong, it should use pinned, not mini.
129 contextMenuModel_.reset(new TabMenuModel(contextMenuDelegate_.get(),
130 [self mini]));
142 contextMenuController_.reset( 131 contextMenuController_.reset(
143 [[MenuController alloc] initWithModel:contextMenuModel_.get() 132 [[MenuController alloc] initWithModel:contextMenuModel_.get()
144 useWithPopUpButtonCell:NO]); 133 useWithPopUpButtonCell:NO]);
145 return [contextMenuController_ menu]; 134 return [contextMenuController_ menu];
146 } 135 }
147 136
148 - (IBAction)closeTab:(id)sender { 137 - (IBAction)closeTab:(id)sender {
149 if ([[self target] respondsToSelector:@selector(closeTab:)]) { 138 if ([[self target] respondsToSelector:@selector(closeTab:)]) {
150 [[self target] performSelector:@selector(closeTab:) 139 [[self target] performSelector:@selector(closeTab:)
151 withObject:[self view]]; 140 withObject:[self view]];
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 // Called by the tabs to determine whether we are in rapid (tab) closure mode. 294 // Called by the tabs to determine whether we are in rapid (tab) closure mode.
306 - (BOOL)inRapidClosureMode { 295 - (BOOL)inRapidClosureMode {
307 if ([[self target] respondsToSelector:@selector(inRapidClosureMode)]) { 296 if ([[self target] respondsToSelector:@selector(inRapidClosureMode)]) {
308 return [[self target] performSelector:@selector(inRapidClosureMode)] ? 297 return [[self target] performSelector:@selector(inRapidClosureMode)] ?
309 YES : NO; 298 YES : NO;
310 } 299 }
311 return NO; 300 return NO;
312 } 301 }
313 302
314 @end 303 @end
OLDNEW
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/gtk/tabs/tab_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698