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

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

Issue 3139003: Merge 55568 - [Mac] Insert the Update Chrome item to existing Wrench menus wh... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/472/src/
Patch Set: Created 10 years, 4 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
« no previous file with comments | « chrome/browser/cocoa/wrench_menu_controller.h ('k') | no next file » | 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 #import "chrome/browser/cocoa/wrench_menu_controller.h" 5 #import "chrome/browser/cocoa/wrench_menu_controller.h"
6 6
7 #include "app/l10n_util.h"
7 #include "app/menus/menu_model.h" 8 #include "app/menus/menu_model.h"
8 #include "base/sys_string_conversions.h" 9 #include "base/sys_string_conversions.h"
9 #include "chrome/app/chrome_dll_resource.h" 10 #include "chrome/app/chrome_dll_resource.h"
10 #include "chrome/browser/browser.h" 11 #include "chrome/browser/browser.h"
11 #include "chrome/browser/browser_window.h" 12 #include "chrome/browser/browser_window.h"
12 #import "chrome/browser/cocoa/toolbar_controller.h" 13 #import "chrome/browser/cocoa/toolbar_controller.h"
13 #include "chrome/browser/wrench_menu_model.h" 14 #include "chrome/browser/wrench_menu_model.h"
15 #include "grit/chromium_strings.h"
16 #include "grit/generated_resources.h"
14 17
15 @interface WrenchMenuController (Private) 18 @interface WrenchMenuController (Private)
16 - (WrenchMenuModel*)wrenchMenuModel; 19 - (WrenchMenuModel*)wrenchMenuModel;
17 - (void)adjustPositioning; 20 - (void)adjustPositioning;
18 @end 21 @end
19 22
20 @implementation WrenchMenuController 23 @implementation WrenchMenuController
21 24
22 - (id)init { 25 - (id)init {
23 self = [super init]; 26 self = [super init];
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 // TODO(rsesek): It'd be great if the zoom buttons didn't have to close the 106 // TODO(rsesek): It'd be great if the zoom buttons didn't have to close the
104 // menu. See http://crbug.com/48679 for more info. 107 // menu. See http://crbug.com/48679 for more info.
105 [menu_ cancelTracking]; 108 [menu_ cancelTracking];
106 [self wrenchMenuModel]->ExecuteCommand(tag); 109 [self wrenchMenuModel]->ExecuteCommand(tag);
107 } 110 }
108 111
109 - (WrenchMenuModel*)wrenchMenuModel { 112 - (WrenchMenuModel*)wrenchMenuModel {
110 return static_cast<WrenchMenuModel*>(model_); 113 return static_cast<WrenchMenuModel*>(model_);
111 } 114 }
112 115
116 // Inserts the update available notification menu item.
117 - (void)insertUpdateAvailableItem {
118 WrenchMenuModel* model = [self wrenchMenuModel];
119 // Don't insert the item multiple times.
120 if (!model || model->GetIndexOfCommandId(IDC_ABOUT) != -1)
121 return;
122
123 // Update the model manually because the model is static because other
124 // platforms always have an About item.
125 int index = model->GetIndexOfCommandId(IDC_OPTIONS) + 1;
126 model->InsertItemAt(index, IDC_ABOUT,
127 l10n_util::GetStringFUTF16(IDS_ABOUT,
128 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
129
130 // The model does not broadcast change notifications to its delegate, so
131 // insert the actual menu item ourselves.
132 NSInteger menuIndex = [[self menu] indexOfItemWithTag:index];
133 [self addItemToMenu:[self menu]
134 atIndex:menuIndex
135 fromModel:model
136 modelIndex:index];
137
138 // Since the tag of each menu item is the index within the model, they need
139 // to be adjusted after insertion.
140 for (NSInteger i = menuIndex + 1; i < [[self menu] numberOfItems]; ++i) {
141 NSMenuItem* item = [[self menu] itemAtIndex:i];
142 [item setTag:[item tag] + 1];
143 }
144 }
145
113 // Fit the localized strings into the Cut/Copy/Paste control, then resize the 146 // Fit the localized strings into the Cut/Copy/Paste control, then resize the
114 // whole menu item accordingly. 147 // whole menu item accordingly.
115 - (void)adjustPositioning { 148 - (void)adjustPositioning {
116 NSRect itemFrame = [editItem_ frame]; 149 NSRect itemFrame = [editItem_ frame];
117 NSRect controlFrame = [editControl_ frame]; 150 NSRect controlFrame = [editControl_ frame];
118 151
119 CGFloat originalControlWidth = NSWidth(controlFrame); 152 CGFloat originalControlWidth = NSWidth(controlFrame);
120 // Maintain the carefully pixel-pushed gap between the edge of the menu and 153 // Maintain the carefully pixel-pushed gap between the edge of the menu and
121 // the rightmost control. 154 // the rightmost control.
122 CGFloat edge = NSWidth(itemFrame) - 155 CGFloat edge = NSWidth(itemFrame) -
123 (controlFrame.origin.x + originalControlWidth); 156 (controlFrame.origin.x + originalControlWidth);
124 157
125 // Resize the edit segmented control to fit the localized strings. 158 // Resize the edit segmented control to fit the localized strings.
126 [editControl_ sizeToFit]; 159 [editControl_ sizeToFit];
127 controlFrame = [editControl_ frame]; 160 controlFrame = [editControl_ frame];
128 CGFloat resizeAmount = NSWidth(controlFrame) - originalControlWidth; 161 CGFloat resizeAmount = NSWidth(controlFrame) - originalControlWidth;
129 162
130 // Adjust the size of the entire menu item to account for changes in the size 163 // Adjust the size of the entire menu item to account for changes in the size
131 // of the segmented control. 164 // of the segmented control.
132 itemFrame.size.width += resizeAmount; 165 itemFrame.size.width += resizeAmount;
133 [editItem_ setFrame:itemFrame]; 166 [editItem_ setFrame:itemFrame];
134 167
135 // Keep the spacing between the right edges of the menu and the control. 168 // Keep the spacing between the right edges of the menu and the control.
136 controlFrame.origin.x = NSWidth(itemFrame) - edge - NSWidth(controlFrame); 169 controlFrame.origin.x = NSWidth(itemFrame) - edge - NSWidth(controlFrame);
137 [editControl_ setFrame:controlFrame]; 170 [editControl_ setFrame:controlFrame];
138 } 171 }
139 172
140 @end // @implementation WrenchMenuController 173 @end // @implementation WrenchMenuController
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/wrench_menu_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698