OLD | NEW |
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/l10n_util.h" |
8 #include "app/menus/menu_model.h" | 8 #include "app/menus/menu_model.h" |
9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
10 #include "chrome/app/chrome_dll_resource.h" | 10 #include "chrome/app/chrome_dll_resource.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 | 56 |
57 @implementation WrenchMenuController | 57 @implementation WrenchMenuController |
58 | 58 |
59 - (id)init { | 59 - (id)init { |
60 if ((self = [super init])) { | 60 if ((self = [super init])) { |
61 observer_.reset(new WrenchMenuControllerInternal::ZoomLevelObserver(self)); | 61 observer_.reset(new WrenchMenuControllerInternal::ZoomLevelObserver(self)); |
62 } | 62 } |
63 return self; | 63 return self; |
64 } | 64 } |
65 | 65 |
66 - (void)setWrenchMenuModel:(WrenchMenuModel*)model { | |
67 wrench_model_ = model; | |
68 [self setModel:model->menu_model()]; | |
69 } | |
70 | |
71 - (void)addItemToMenu:(NSMenu*)menu | 66 - (void)addItemToMenu:(NSMenu*)menu |
72 atIndex:(NSInteger)index | 67 atIndex:(NSInteger)index |
73 fromModel:(menus::MenuModel*)model | 68 fromModel:(menus::MenuModel*)model |
74 modelIndex:(int)modelIndex { | 69 modelIndex:(int)modelIndex { |
75 // Non-button item types should be built as normal items. | 70 // Non-button item types should be built as normal items. |
76 menus::MenuModel::ItemType type = model->GetTypeAt(modelIndex); | 71 menus::MenuModel::ItemType type = model->GetTypeAt(modelIndex); |
77 if (type != menus::MenuModel::TYPE_BUTTON_ITEM) { | 72 if (type != menus::MenuModel::TYPE_BUTTON_ITEM) { |
78 [super addItemToMenu:menu | 73 [super addItemToMenu:menu |
79 atIndex:index | 74 atIndex:index |
80 fromModel:model | 75 fromModel:model |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 withObject:[NSNumber numberWithInt:tag] | 159 withObject:[NSNumber numberWithInt:tag] |
165 afterDelay:0.0]; | 160 afterDelay:0.0]; |
166 } | 161 } |
167 | 162 |
168 // Used to perform the actual dispatch on the outermost runloop. | 163 // Used to perform the actual dispatch on the outermost runloop. |
169 - (void)performCommandDispatch:(NSNumber*)tag { | 164 - (void)performCommandDispatch:(NSNumber*)tag { |
170 [self wrenchMenuModel]->ExecuteCommand([tag intValue]); | 165 [self wrenchMenuModel]->ExecuteCommand([tag intValue]); |
171 } | 166 } |
172 | 167 |
173 - (WrenchMenuModel*)wrenchMenuModel { | 168 - (WrenchMenuModel*)wrenchMenuModel { |
174 return wrench_model_; | 169 return static_cast<WrenchMenuModel*>(model_); |
| 170 } |
| 171 |
| 172 // Inserts the update available notification menu item. |
| 173 - (void)insertUpdateAvailableItem { |
| 174 WrenchMenuModel* model = [self wrenchMenuModel]; |
| 175 // Don't insert the item multiple times. |
| 176 if (!model || model->GetIndexOfCommandId(IDC_ABOUT) != -1) |
| 177 return; |
| 178 |
| 179 // Update the model manually because the model is static because other |
| 180 // platforms always have an About item. |
| 181 int index = model->GetIndexOfCommandId(IDC_OPTIONS) + 1; |
| 182 model->InsertItemAt(index, IDC_ABOUT, |
| 183 l10n_util::GetStringFUTF16(IDS_ABOUT, |
| 184 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); |
| 185 |
| 186 // The model does not broadcast change notifications to its delegate, so |
| 187 // insert the actual menu item ourselves. |
| 188 NSInteger menuIndex = [[self menu] indexOfItemWithTag:index]; |
| 189 [self addItemToMenu:[self menu] |
| 190 atIndex:menuIndex |
| 191 fromModel:model |
| 192 modelIndex:index]; |
| 193 |
| 194 // Since the tag of each menu item is the index within the model, they need |
| 195 // to be adjusted after insertion. |
| 196 for (NSInteger i = menuIndex + 1; i < [[self menu] numberOfItems]; ++i) { |
| 197 NSMenuItem* item = [[self menu] itemAtIndex:i]; |
| 198 [item setTag:[item tag] + 1]; |
| 199 } |
175 } | 200 } |
176 | 201 |
177 // Fit the localized strings into the Cut/Copy/Paste control, then resize the | 202 // Fit the localized strings into the Cut/Copy/Paste control, then resize the |
178 // whole menu item accordingly. | 203 // whole menu item accordingly. |
179 - (void)adjustPositioning { | 204 - (void)adjustPositioning { |
180 const CGFloat kButtonPadding = 12; | 205 const CGFloat kButtonPadding = 12; |
181 CGFloat delta = 0; | 206 CGFloat delta = 0; |
182 | 207 |
183 // Go through the three buttons from right-to-left, adjusting the size to fit | 208 // Go through the three buttons from right-to-left, adjusting the size to fit |
184 // the localized strings while keeping them all aligned on their horizontal | 209 // the localized strings while keeping them all aligned on their horizontal |
(...skipping 30 matching lines...) Expand all Loading... |
215 parentFrame.size.width += delta; | 240 parentFrame.size.width += delta; |
216 parentFrame.origin.x -= delta; | 241 parentFrame.origin.x -= delta; |
217 [[editCut_ superview] setFrame:parentFrame]; | 242 [[editCut_ superview] setFrame:parentFrame]; |
218 } | 243 } |
219 | 244 |
220 - (NSButton*)zoomDisplay { | 245 - (NSButton*)zoomDisplay { |
221 return zoomDisplay_; | 246 return zoomDisplay_; |
222 } | 247 } |
223 | 248 |
224 @end // @implementation WrenchMenuController | 249 @end // @implementation WrenchMenuController |
OLD | NEW |