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

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

Issue 2952004: [Mac] Finish implementation of App Tabs. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 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
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"
11 #import "chrome/browser/cocoa/tab_view.h" 11 #import "chrome/browser/cocoa/tab_view.h"
12 #import "chrome/browser/cocoa/themed_window.h" 12 #import "chrome/browser/cocoa/themed_window.h"
13 #import "chrome/common/extensions/extension.h" 13 #import "chrome/common/extensions/extension.h"
14 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
15 15
16 @implementation TabController 16 @implementation TabController
17 17
18 @synthesize action = action_; 18 @synthesize action = action_;
19 @synthesize app = app_; 19 @synthesize app = app_;
20 @synthesize loadingState = loadingState_; 20 @synthesize loadingState = loadingState_;
21 @synthesize mini = mini_; 21 @synthesize mini = mini_;
22 @synthesize phantom = phantom_; 22 @synthesize phantom = phantom_;
23 @synthesize pinned = pinned_; 23 @synthesize pinned = pinned_;
24 @synthesize target = target_; 24 @synthesize target = target_;
25 25
26 namespace {
27 const CGFloat kAppIconTopOffsetPx = 2.0;
28 } // anonymous namespace
29
30 namespace TabControllerInternal { 26 namespace TabControllerInternal {
31 27
32 // A C++ delegate that handles enabling/disabling menu items and handling when 28 // A C++ delegate that handles enabling/disabling menu items and handling when
33 // a menu command is chosen. Also fixes up the menu item label for "pin/unpin 29 // a menu command is chosen. Also fixes up the menu item label for "pin/unpin
34 // tab". 30 // tab".
35 class MenuDelegate : public menus::SimpleMenuModel::Delegate { 31 class MenuDelegate : public menus::SimpleMenuModel::Delegate {
36 public: 32 public:
37 explicit MenuDelegate(id<TabControllerTarget> target, TabController* owner) 33 explicit MenuDelegate(id<TabControllerTarget> target, TabController* owner)
38 : target_(target), 34 : target_(target),
39 owner_(owner) {} 35 owner_(owner) {}
(...skipping 21 matching lines...) Expand all
61 57
62 } // TabControllerInternal namespace 58 } // TabControllerInternal namespace
63 59
64 // The min widths match the windows values and are sums of left + right 60 // The min widths match the windows values and are sums of left + right
65 // padding, of which we have no comparable constants (we draw using paths, not 61 // padding, of which we have no comparable constants (we draw using paths, not
66 // images). The selected tab width includes the close button width. 62 // images). The selected tab width includes the close button width.
67 + (CGFloat)minTabWidth { return 31; } 63 + (CGFloat)minTabWidth { return 31; }
68 + (CGFloat)minSelectedTabWidth { return 46; } 64 + (CGFloat)minSelectedTabWidth { return 46; }
69 + (CGFloat)maxTabWidth { return 220; } 65 + (CGFloat)maxTabWidth { return 220; }
70 + (CGFloat)miniTabWidth { return 53; } 66 + (CGFloat)miniTabWidth { return 53; }
71 + (CGFloat)appTabWidth { return 46; } 67 + (CGFloat)appTabWidth { return 66; }
72 68
73 - (TabView*)tabView { 69 - (TabView*)tabView {
74 return static_cast<TabView*>([self view]); 70 return static_cast<TabView*>([self view]);
75 } 71 }
76 72
77 - (id)init { 73 - (id)init {
78 self = [super initWithNibName:@"TabView" bundle:mac_util::MainAppBundle()]; 74 self = [super initWithNibName:@"TabView" bundle:mac_util::MainAppBundle()];
79 if (self != nil) { 75 if (self != nil) {
80 isIconShowing_ = YES; 76 isIconShowing_ = YES;
81 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; 77 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 [self internalSetSelected:selected_]; 123 [self internalSetSelected:selected_];
128 } 124 }
129 125
130 // Called when Cocoa wants to display the context menu. Lazily instantiate 126 // Called when Cocoa wants to display the context menu. Lazily instantiate
131 // the menu based off of the cross-platform model. Re-create the menu and 127 // the menu based off of the cross-platform model. Re-create the menu and
132 // model every time to get the correct labels and enabling. 128 // model every time to get the correct labels and enabling.
133 - (NSMenu*)menu { 129 - (NSMenu*)menu {
134 contextMenuDelegate_.reset( 130 contextMenuDelegate_.reset(
135 new TabControllerInternal::MenuDelegate(target_, self)); 131 new TabControllerInternal::MenuDelegate(target_, self));
136 contextMenuModel_.reset(new TabMenuModel(contextMenuDelegate_.get(), 132 contextMenuModel_.reset(new TabMenuModel(contextMenuDelegate_.get(),
137 [self pinned], false, true)); 133 [self pinned],
134 false, // allow_toolbar_toggle
Mark Mentovai 2010/07/14 18:40:28 OCD: line up the comments.
135 true)); // is_toolbar_visible
136
138 contextMenuController_.reset( 137 contextMenuController_.reset(
139 [[MenuController alloc] initWithModel:contextMenuModel_.get() 138 [[MenuController alloc] initWithModel:contextMenuModel_.get()
140 useWithPopUpButtonCell:NO]); 139 useWithPopUpButtonCell:NO]);
141 return [contextMenuController_ menu]; 140 return [contextMenuController_ menu];
142 } 141 }
143 142
144 - (IBAction)closeTab:(id)sender { 143 - (IBAction)closeTab:(id)sender {
145 if ([[self target] respondsToSelector:@selector(closeTab:)]) { 144 if ([[self target] respondsToSelector:@selector(closeTab:)]) {
146 [[self target] performSelector:@selector(closeTab:) 145 [[self target] performSelector:@selector(closeTab:)
147 withObject:[self view]]; 146 withObject:[self view]];
(...skipping 18 matching lines...) Expand all
166 - (BOOL)selected { 165 - (BOOL)selected {
167 return selected_; 166 return selected_;
168 } 167 }
169 168
170 - (void)setIconView:(NSView*)iconView { 169 - (void)setIconView:(NSView*)iconView {
171 [iconView_ removeFromSuperview]; 170 [iconView_ removeFromSuperview];
172 iconView_ = iconView; 171 iconView_ = iconView;
173 if ([self app]) { 172 if ([self app]) {
174 NSRect appIconFrame = [iconView frame]; 173 NSRect appIconFrame = [iconView frame];
175 appIconFrame.origin = originalIconFrame_.origin; 174 appIconFrame.origin = originalIconFrame_.origin;
176 // Adjust the position to prevent clipping due to the icon's larger size.
177 appIconFrame.origin.y -= kAppIconTopOffsetPx;
178 // Center the icon. 175 // Center the icon.
179 appIconFrame.origin.x = ([TabController appTabWidth] - 176 appIconFrame.origin.x = ([TabController appTabWidth] -
180 NSWidth(appIconFrame)) / 2.0; 177 NSWidth(appIconFrame)) / 2.0;
181 [iconView setFrame:appIconFrame]; 178 [iconView setFrame:appIconFrame];
182 } else { 179 } else {
183 [iconView_ setFrame:originalIconFrame_]; 180 [iconView_ setFrame:originalIconFrame_];
184 } 181 }
185 // Ensure that the icon is suppressed if no icon is set or if the tab is too 182 // Ensure that the icon is suppressed if no icon is set or if the tab is too
186 // narrow to display one. 183 // narrow to display one.
187 [self updateVisibility]; 184 [self updateVisibility];
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 // Called by the tabs to determine whether we are in rapid (tab) closure mode. 308 // Called by the tabs to determine whether we are in rapid (tab) closure mode.
312 - (BOOL)inRapidClosureMode { 309 - (BOOL)inRapidClosureMode {
313 if ([[self target] respondsToSelector:@selector(inRapidClosureMode)]) { 310 if ([[self target] respondsToSelector:@selector(inRapidClosureMode)]) {
314 return [[self target] performSelector:@selector(inRapidClosureMode)] ? 311 return [[self target] performSelector:@selector(inRapidClosureMode)] ?
315 YES : NO; 312 YES : NO;
316 } 313 }
317 return NO; 314 return NO;
318 } 315 }
319 316
320 @end 317 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698