Chromium Code Reviews| 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/menus/menu_model.h" | 7 #include "app/menus/menu_model.h" |
| 8 #include "base/sys_string_conversions.h" | 8 #include "base/sys_string_conversions.h" |
| 9 #include "chrome/app/chrome_dll_resource.h" | 9 #include "chrome/app/chrome_dll_resource.h" |
| 10 #include "chrome/browser/browser.h" | 10 #include "chrome/browser/browser.h" |
| 11 #include "chrome/browser/browser_window.h" | 11 #include "chrome/browser/browser_window.h" |
| 12 #import "chrome/browser/cocoa/toolbar_controller.h" | 12 #import "chrome/browser/cocoa/toolbar_controller.h" |
| 13 #include "chrome/browser/wrench_menu_model.h" | 13 #include "chrome/browser/wrench_menu_model.h" |
| 14 | 14 |
| 15 @interface WrenchMenuController (Private) | 15 @interface WrenchMenuController (Private) |
| 16 - (WrenchMenuModel*)wrenchMenuModel; | 16 - (WrenchMenuModel*)wrenchMenuModel; |
| 17 - (void)adjustPositioning; | 17 - (void)adjustPositioning; |
| 18 - (void)dispatchCommandInternal:(NSNumber*)tag; | |
| 18 @end | 19 @end |
| 19 | 20 |
| 20 @implementation WrenchMenuController | 21 @implementation WrenchMenuController |
| 21 | 22 |
| 22 - (id)init { | 23 - (id)init { |
| 23 self = [super init]; | 24 self = [super init]; |
| 24 return self; | 25 return self; |
| 25 } | 26 } |
| 26 | 27 |
| 27 - (void)addItemToMenu:(NSMenu*)menu | 28 - (void)addItemToMenu:(NSMenu*)menu |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 // NSSegmentedControls (used for the Edit item) need a little help to get the | 91 // NSSegmentedControls (used for the Edit item) need a little help to get the |
| 91 // command_id of the pressed item. | 92 // command_id of the pressed item. |
| 92 if ([sender isKindOfClass:[NSSegmentedControl class]]) | 93 if ([sender isKindOfClass:[NSSegmentedControl class]]) |
| 93 tag = [[sender cell] tagForSegment:[sender selectedSegment]]; | 94 tag = [[sender cell] tagForSegment:[sender selectedSegment]]; |
| 94 | 95 |
| 95 // The custom views within the Wrench menu are abnormal and keep the menu open | 96 // The custom views within the Wrench menu are abnormal and keep the menu open |
| 96 // after a target-action. Close the menu manually. | 97 // after a target-action. Close the menu manually. |
| 97 // TODO(rsesek): It'd be great if the zoom buttons didn't have to close the | 98 // TODO(rsesek): It'd be great if the zoom buttons didn't have to close the |
| 98 // menu. See http://crbug.com/48679 for more info. | 99 // menu. See http://crbug.com/48679 for more info. |
| 99 [menu_ cancelTracking]; | 100 [menu_ cancelTracking]; |
| 100 [self wrenchMenuModel]->ExecuteCommand(tag); | 101 // Executing certain commands from the nested run loop of the menu can lead |
| 102 // to wonky behavior. To avoid this, schedule the dispatch on the outermost | |
|
Nico
2010/07/21 15:15:56
s/ior/ior (e.g. http://crbug.com/$BUG)/
| |
| 103 // run loop. | |
| 104 [self performSelector:@selector(dispatchCommandInternal:) | |
| 105 withObject:[NSNumber numberWithInt:tag] | |
| 106 afterDelay:0.0]; | |
| 107 } | |
| 108 | |
| 109 // Used to perform the actual dispatch on the outermost runloop. | |
| 110 - (void)dispatchCommandInternal:(NSNumber*)tag { | |
| 111 [self wrenchMenuModel]->ExecuteCommand([tag intValue]); | |
| 101 } | 112 } |
| 102 | 113 |
| 103 - (WrenchMenuModel*)wrenchMenuModel { | 114 - (WrenchMenuModel*)wrenchMenuModel { |
| 104 return static_cast<WrenchMenuModel*>(model_); | 115 return static_cast<WrenchMenuModel*>(model_); |
| 105 } | 116 } |
| 106 | 117 |
| 107 // Fit the localized strings into the Cut/Copy/Paste control, then resize the | 118 // Fit the localized strings into the Cut/Copy/Paste control, then resize the |
| 108 // whole menu item accordingly. | 119 // whole menu item accordingly. |
| 109 - (void)adjustPositioning { | 120 - (void)adjustPositioning { |
| 110 NSRect itemFrame = [editItem_ frame]; | 121 NSRect itemFrame = [editItem_ frame]; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 125 // of the segmented control. | 136 // of the segmented control. |
| 126 itemFrame.size.width += resizeAmount; | 137 itemFrame.size.width += resizeAmount; |
| 127 [editItem_ setFrame:itemFrame]; | 138 [editItem_ setFrame:itemFrame]; |
| 128 | 139 |
| 129 // Keep the spacing between the right edges of the menu and the control. | 140 // Keep the spacing between the right edges of the menu and the control. |
| 130 controlFrame.origin.x = NSWidth(itemFrame) - edge - NSWidth(controlFrame); | 141 controlFrame.origin.x = NSWidth(itemFrame) - edge - NSWidth(controlFrame); |
| 131 [editControl_ setFrame:controlFrame]; | 142 [editControl_ setFrame:controlFrame]; |
| 132 } | 143 } |
| 133 | 144 |
| 134 @end // @implementation WrenchMenuController | 145 @end // @implementation WrenchMenuController |
| OLD | NEW |