diff options
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/app/chrome_dll_resource.h | 1 | ||||
-rw-r--r-- | chrome/app/nibs/Toolbar.xib | 689 | ||||
-rw-r--r-- | chrome/browser/cocoa/menu_controller.h | 26 | ||||
-rw-r--r-- | chrome/browser/cocoa/menu_controller.mm | 46 | ||||
-rw-r--r-- | chrome/browser/cocoa/menu_controller_unittest.mm | 20 | ||||
-rw-r--r-- | chrome/browser/cocoa/toolbar_controller.h | 8 | ||||
-rw-r--r-- | chrome/browser/cocoa/toolbar_controller.mm | 11 | ||||
-rw-r--r-- | chrome/browser/cocoa/wrench_menu_controller.h | 46 | ||||
-rw-r--r-- | chrome/browser/cocoa/wrench_menu_controller.mm | 127 | ||||
-rw-r--r-- | chrome/browser/cocoa/wrench_menu_controller_unittest.mm | 81 | ||||
-rw-r--r-- | chrome/browser/wrench_menu_model.cc | 12 | ||||
-rw-r--r-- | chrome/browser/wrench_menu_model.h | 8 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 1 |
14 files changed, 1040 insertions, 38 deletions
diff --git a/chrome/app/chrome_dll_resource.h b/chrome/app/chrome_dll_resource.h index df3a67e..b9991f3 100644 --- a/chrome/app/chrome_dll_resource.h +++ b/chrome/app/chrome_dll_resource.h @@ -162,6 +162,7 @@ #define IDC_COPY 36001 #define IDC_COPY_URL 36002 #define IDC_PASTE 36003 +#define IDC_EDIT_MENU 36004 // Find-in-page #define IDC_FIND 37000 diff --git a/chrome/app/nibs/Toolbar.xib b/chrome/app/nibs/Toolbar.xib index 95467eb..c805f29 100644 --- a/chrome/app/nibs/Toolbar.xib +++ b/chrome/app/nibs/Toolbar.xib @@ -2,17 +2,18 @@ <archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.10"> <data> <int key="IBDocument.SystemTarget">1050</int> - <string key="IBDocument.SystemVersion">10F569</string> - <string key="IBDocument.InterfaceBuilderVersion">761</string> + <string key="IBDocument.SystemVersion">10D2063a</string> + <string key="IBDocument.InterfaceBuilderVersion">762</string> <string key="IBDocument.AppKitVersion">1038.29</string> - <string key="IBDocument.HIToolboxVersion">461.00</string> + <string key="IBDocument.HIToolboxVersion">460.00</string> <object class="NSMutableDictionary" key="IBDocument.PluginVersions"> <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string> - <string key="NS.object.0">761</string> + <string key="NS.object.0">762</string> </object> <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> <bool key="EncodedWithXMLCoder">YES</bool> - <integer value="1"/> + <integer value="156"/> + <integer value="208"/> </object> <object class="NSArray" key="IBDocument.PluginDependencies"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -39,7 +40,7 @@ <string key="NSClassName">NSApplication</string> </object> <object class="NSCustomView" id="928520650"> - <reference key="NSNextResponder"/> + <nil key="NSNextResponder"/> <int key="NSvFlags">266</int> <object class="NSMutableArray" key="NSSubviews"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -81,7 +82,7 @@ <int key="NSColorSpace">6</int> <string key="NSCatalogName">System</string> <string key="NSColorName">textColor</string> - <object class="NSColor" key="NSColor"> + <object class="NSColor" key="NSColor" id="420298952"> <int key="NSColorSpace">3</int> <bytes key="NSWhite">MAA</bytes> </object> @@ -218,7 +219,6 @@ </object> </object> <string key="NSFrameSize">{608, 34}</string> - <reference key="NSSuperview"/> <string key="NSClassName">ToolbarView</string> </object> <object class="NSCustomObject" id="1044322163"> @@ -227,6 +227,246 @@ <object class="NSUserDefaultsController" id="306232897"> <bool key="NSSharedInstance">YES</bool> </object> + <object class="NSCustomView" id="974949794"> + <reference key="NSNextResponder"/> + <int key="NSvFlags">266</int> + <object class="NSMutableArray" key="NSSubviews"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSCustomView" id="685460050"> + <reference key="NSNextResponder" ref="974949794"/> + <int key="NSvFlags">294</int> + <object class="NSMutableArray" key="NSSubviews"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSTextField" id="950178043"> + <reference key="NSNextResponder" ref="685460050"/> + <int key="NSvFlags">270</int> + <string key="NSFrame">{{17, 20}, {63, 18}}</string> + <reference key="NSSuperview" ref="685460050"/> + <reference key="NSNextKeyView" ref="311802185"/> + <bool key="NSEnabled">YES</bool> + <object class="NSTextFieldCell" key="NSCell" id="881623077"> + <int key="NSCellFlags">68288064</int> + <int key="NSCellFlags2">272630784</int> + <string key="NSContents">^IDS_EDIT</string> + <object class="NSFont" key="NSSupport" id="530887179"> + <string key="NSName">LucidaGrande-Bold</string> + <double key="NSSize">14</double> + <int key="NSfFlags">16</int> + </object> + <reference key="NSControlView" ref="950178043"/> + <object class="NSColor" key="NSBackgroundColor" id="738720100"> + <int key="NSColorSpace">6</int> + <string key="NSCatalogName">System</string> + <string key="NSColorName">controlColor</string> + <object class="NSColor" key="NSColor"> + <int key="NSColorSpace">3</int> + <bytes key="NSWhite">MC42NjY2NjY2NjY3AA</bytes> + </object> + </object> + <object class="NSColor" key="NSTextColor" id="722572692"> + <int key="NSColorSpace">6</int> + <string key="NSCatalogName">System</string> + <string key="NSColorName">controlTextColor</string> + <reference key="NSColor" ref="420298952"/> + </object> + </object> + </object> + </object> + <string key="NSFrame">{{2, -18}, {100, 58}}</string> + <reference key="NSSuperview" ref="974949794"/> + <string key="NSClassName">GTMWidthBasedTweaker</string> + </object> + <object class="NSSegmentedControl" id="311802185"> + <reference key="NSNextResponder" ref="974949794"/> + <int key="NSvFlags">265</int> + <string key="NSFrame">{{134, 0}, {126, 21}}</string> + <reference key="NSSuperview" ref="974949794"/> + <bool key="NSEnabled">YES</bool> + <object class="NSSegmentedCell" key="NSCell" id="208223583"> + <int key="NSCellFlags">-2080244224</int> + <int key="NSCellFlags2">131072</int> + <object class="NSFont" key="NSSupport" id="26"> + <string key="NSName">LucidaGrande</string> + <double key="NSSize">11</double> + <int key="NSfFlags">3100</int> + </object> + <reference key="NSControlView" ref="311802185"/> + <object class="NSMutableArray" key="NSSegmentImages"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSSegmentItem"> + <string key="NSSegmentItemLabel">^IDS_CUT</string> + <int key="NSSegmentItemTag">36000</int> + <int key="NSSegmentItemImageScaling">0</int> + </object> + <object class="NSSegmentItem"> + <string key="NSSegmentItemLabel">^IDS_COPY</string> + <int key="NSSegmentItemTag">36001</int> + <int key="NSSegmentItemImageScaling">0</int> + </object> + <object class="NSSegmentItem"> + <string key="NSSegmentItemLabel">^IDS_PASTE</string> + <int key="NSSegmentItemTag">36003</int> + <int key="NSSegmentItemImageScaling">0</int> + </object> + </object> + <int key="NSTrackingMode">2</int> + <int key="NSSegmentStyle">6</int> + </object> + </object> + </object> + <string key="NSFrameSize">{275, 20}</string> + <reference key="NSSuperview"/> + <reference key="NSNextKeyView" ref="950178043"/> + <string key="NSClassName">NSView</string> + </object> + <object class="NSCustomView" id="388169352"> + <reference key="NSNextResponder"/> + <int key="NSvFlags">266</int> + <object class="NSMutableArray" key="NSSubviews"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSCustomView" id="1015660087"> + <reference key="NSNextResponder" ref="388169352"/> + <int key="NSvFlags">265</int> + <object class="NSMutableArray" key="NSSubviews"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSButton" id="545855108"> + <reference key="NSNextResponder" ref="1015660087"/> + <int key="NSvFlags">265</int> + <string key="NSFrame">{{108, 19}, {21, 21}}</string> + <reference key="NSSuperview" ref="1015660087"/> + <int key="NSTag">34030</int> + <bool key="NSEnabled">YES</bool> + <object class="NSButtonCell" key="NSCell" id="1052876110"> + <int key="NSCellFlags">67239424</int> + <int key="NSCellFlags2">134348800</int> + <string key="NSContents"/> + <reference key="NSSupport" ref="26"/> + <reference key="NSControlView" ref="545855108"/> + <int key="NSButtonFlags">-2033434369</int> + <int key="NSButtonFlags2">162</int> + <object class="NSCustomResource" key="NSNormalImage"> + <string key="NSClassName">NSImage</string> + <string key="NSResourceName">NSEnterFullScreenTemplate</string> + </object> + <string key="NSAlternateContents"/> + <string key="NSKeyEquivalent"/> + <int key="NSPeriodicDelay">200</int> + <int key="NSPeriodicInterval">25</int> + </object> + </object> + <object class="NSButton" id="272247480"> + <reference key="NSNextResponder" ref="1015660087"/> + <int key="NSvFlags">265</int> + <string key="NSFrame">{{23, 19}, {45, 21}}</string> + <reference key="NSSuperview" ref="1015660087"/> + <int key="NSTag">38004</int> + <bool key="NSEnabled">YES</bool> + <object class="NSButtonCell" key="NSCell" id="396836830"> + <int key="NSCellFlags">604110336</int> + <int key="NSCellFlags2">167903232</int> + <string key="NSContents">100%</string> + <reference key="NSSupport" ref="26"/> + <reference key="NSControlView" ref="272247480"/> + <int key="NSButtonFlags">-2033434369</int> + <int key="NSButtonFlags2">162</int> + <string key="NSAlternateContents"/> + <string key="NSKeyEquivalent"/> + <int key="NSPeriodicDelay">200</int> + <int key="NSPeriodicInterval">25</int> + </object> + </object> + <object class="NSButton" id="529291232"> + <reference key="NSNextResponder" ref="1015660087"/> + <int key="NSvFlags">265</int> + <string key="NSFrame">{{3, 19}, {21, 21}}</string> + <reference key="NSSuperview" ref="1015660087"/> + <int key="NSTag">38001</int> + <bool key="NSEnabled">YES</bool> + <object class="NSButtonCell" key="NSCell" id="1044796389"> + <int key="NSCellFlags">67239424</int> + <int key="NSCellFlags2">134348800</int> + <string key="NSContents"/> + <reference key="NSSupport" ref="26"/> + <reference key="NSControlView" ref="529291232"/> + <int key="NSButtonFlags">-2033434369</int> + <int key="NSButtonFlags2">162</int> + <object class="NSCustomResource" key="NSNormalImage"> + <string key="NSClassName">NSImage</string> + <string key="NSResourceName">NSAddTemplate</string> + </object> + <string key="NSAlternateContents"/> + <string key="NSKeyEquivalent"/> + <int key="NSPeriodicDelay">200</int> + <int key="NSPeriodicInterval">25</int> + </object> + </object> + <object class="NSButton" id="977694438"> + <reference key="NSNextResponder" ref="1015660087"/> + <int key="NSvFlags">265</int> + <string key="NSFrame">{{67, 19}, {21, 21}}</string> + <reference key="NSSuperview" ref="1015660087"/> + <reference key="NSNextKeyView" ref="545855108"/> + <int key="NSTag">38003</int> + <bool key="NSEnabled">YES</bool> + <object class="NSButtonCell" key="NSCell" id="325020598"> + <int key="NSCellFlags">67239424</int> + <int key="NSCellFlags2">134348800</int> + <string key="NSContents"/> + <reference key="NSSupport" ref="26"/> + <reference key="NSControlView" ref="977694438"/> + <int key="NSButtonFlags">-2033434369</int> + <int key="NSButtonFlags2">162</int> + <object class="NSCustomResource" key="NSNormalImage"> + <string key="NSClassName">NSImage</string> + <string key="NSResourceName">NSRemoveTemplate</string> + </object> + <string key="NSAlternateContents"/> + <string key="NSKeyEquivalent"/> + <int key="NSPeriodicDelay">200</int> + <int key="NSPeriodicInterval">25</int> + </object> + </object> + </object> + <string key="NSFrame">{{131, -19}, {149, 59}}</string> + <reference key="NSSuperview" ref="388169352"/> + <string key="NSClassName">NSView</string> + </object> + <object class="NSCustomView" id="38627075"> + <reference key="NSNextResponder" ref="388169352"/> + <int key="NSvFlags">294</int> + <object class="NSMutableArray" key="NSSubviews"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSTextField" id="370565926"> + <reference key="NSNextResponder" ref="38627075"/> + <int key="NSvFlags">270</int> + <string key="NSFrame">{{17, 20}, {82, 18}}</string> + <reference key="NSSuperview" ref="38627075"/> + <reference key="NSNextKeyView" ref="529291232"/> + <bool key="NSEnabled">YES</bool> + <object class="NSTextFieldCell" key="NSCell" id="582980719"> + <int key="NSCellFlags">68288064</int> + <int key="NSCellFlags2">272630784</int> + <string key="NSContents">^IDS_ZOOM_MENU</string> + <reference key="NSSupport" ref="530887179"/> + <reference key="NSControlView" ref="370565926"/> + <reference key="NSBackgroundColor" ref="738720100"/> + <reference key="NSTextColor" ref="722572692"/> + </object> + </object> + </object> + <string key="NSFrame">{{2, -18}, {103, 58}}</string> + <reference key="NSSuperview" ref="388169352"/> + <string key="NSClassName">GTMWidthBasedTweaker</string> + </object> + </object> + <string key="NSFrameSize">{275, 20}</string> + <reference key="NSSuperview"/> + <reference key="NSNextKeyView" ref="370565926"/> + <string key="NSClassName">NSView</string> + </object> + <object class="NSCustomObject" id="301580502"> + <string key="NSClassName">WrenchMenuController</string> + </object> </object> <object class="IBObjectContainer" key="IBDocument.Objects"> <object class="NSMutableArray" key="connectionRecords"> @@ -343,6 +583,150 @@ </object> <int key="connectionID">155</int> </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">otherObjectToLocalize_</string> + <reference key="source" ref="1044322163"/> + <reference key="destination" ref="974949794"/> + </object> + <int key="connectionID">174</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">yetAnotherObjectToLocalize_</string> + <reference key="source" ref="1044322163"/> + <reference key="destination" ref="388169352"/> + </object> + <int key="connectionID">175</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">zoomItem_</string> + <reference key="source" ref="301580502"/> + <reference key="destination" ref="388169352"/> + </object> + <int key="connectionID">190</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">editItem_</string> + <reference key="source" ref="301580502"/> + <reference key="destination" ref="974949794"/> + </object> + <int key="connectionID">191</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">zoomPlus_</string> + <reference key="source" ref="301580502"/> + <reference key="destination" ref="529291232"/> + </object> + <int key="connectionID">192</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">zoomMinus_</string> + <reference key="source" ref="301580502"/> + <reference key="destination" ref="977694438"/> + </object> + <int key="connectionID">193</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">zoomFullScreen_</string> + <reference key="source" ref="301580502"/> + <reference key="destination" ref="545855108"/> + </object> + <int key="connectionID">194</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">zoomDisplay_</string> + <reference key="source" ref="301580502"/> + <reference key="destination" ref="272247480"/> + </object> + <int key="connectionID">195</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">editControl_</string> + <reference key="source" ref="301580502"/> + <reference key="destination" ref="311802185"/> + </object> + <int key="connectionID">196</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBActionConnection" key="connection"> + <string key="label">dispatchWrenchMenuCommand:</string> + <reference key="source" ref="301580502"/> + <reference key="destination" ref="529291232"/> + </object> + <int key="connectionID">197</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBActionConnection" key="connection"> + <string key="label">dispatchWrenchMenuCommand:</string> + <reference key="source" ref="301580502"/> + <reference key="destination" ref="977694438"/> + </object> + <int key="connectionID">198</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBActionConnection" key="connection"> + <string key="label">dispatchWrenchMenuCommand:</string> + <reference key="source" ref="301580502"/> + <reference key="destination" ref="545855108"/> + </object> + <int key="connectionID">199</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBActionConnection" key="connection"> + <string key="label">dispatchWrenchMenuCommand:</string> + <reference key="source" ref="301580502"/> + <reference key="destination" ref="311802185"/> + </object> + <int key="connectionID">200</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">wrenchMenuController_</string> + <reference key="source" ref="1001"/> + <reference key="destination" ref="301580502"/> + </object> + <int key="connectionID">201</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">viewToSlide_</string> + <reference key="source" ref="685460050"/> + <reference key="destination" ref="311802185"/> + </object> + <int key="connectionID">205</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">viewToResize_</string> + <reference key="source" ref="685460050"/> + <reference key="destination" ref="974949794"/> + </object> + <int key="connectionID">206</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">viewToSlide_</string> + <reference key="source" ref="38627075"/> + <reference key="destination" ref="1015660087"/> + </object> + <int key="connectionID">209</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">viewToResize_</string> + <reference key="source" ref="38627075"/> + <reference key="destination" ref="388169352"/> + </object> + <int key="connectionID">210</int> + </object> </object> <object class="IBMutableOrderedSet" key="objectRecords"> <object class="NSArray" key="orderedObjects"> @@ -486,6 +870,161 @@ <reference key="parent" ref="928520650"/> <string key="objectName">Browser Actions Container</string> </object> + <object class="IBObjectRecord"> + <int key="objectID">156</int> + <reference key="object" ref="974949794"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="311802185"/> + <reference ref="685460050"/> + </object> + <reference key="parent" ref="0"/> + <string key="objectName">Wrench Menu - Edit Item</string> + </object> + <object class="IBObjectRecord"> + <int key="objectID">157</int> + <reference key="object" ref="388169352"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="38627075"/> + <reference ref="1015660087"/> + </object> + <reference key="parent" ref="0"/> + <string key="objectName">Wrench Menu - Zoom Item</string> + </object> + <object class="IBObjectRecord"> + <int key="objectID">169</int> + <reference key="object" ref="311802185"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="208223583"/> + </object> + <reference key="parent" ref="974949794"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">170</int> + <reference key="object" ref="208223583"/> + <reference key="parent" ref="311802185"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">189</int> + <reference key="object" ref="301580502"/> + <reference key="parent" ref="0"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">204</int> + <reference key="object" ref="685460050"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="950178043"/> + </object> + <reference key="parent" ref="974949794"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">168</int> + <reference key="object" ref="950178043"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="881623077"/> + </object> + <reference key="parent" ref="685460050"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">171</int> + <reference key="object" ref="881623077"/> + <reference key="parent" ref="950178043"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">207</int> + <reference key="object" ref="38627075"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="370565926"/> + </object> + <reference key="parent" ref="388169352"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">162</int> + <reference key="object" ref="370565926"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="582980719"/> + </object> + <reference key="parent" ref="38627075"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">163</int> + <reference key="object" ref="582980719"/> + <reference key="parent" ref="370565926"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">208</int> + <reference key="object" ref="1015660087"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="977694438"/> + <reference ref="529291232"/> + <reference ref="272247480"/> + <reference ref="545855108"/> + </object> + <reference key="parent" ref="388169352"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">159</int> + <reference key="object" ref="977694438"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="325020598"/> + </object> + <reference key="parent" ref="1015660087"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">166</int> + <reference key="object" ref="325020598"/> + <reference key="parent" ref="977694438"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">161</int> + <reference key="object" ref="529291232"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="1044796389"/> + </object> + <reference key="parent" ref="1015660087"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">164</int> + <reference key="object" ref="1044796389"/> + <reference key="parent" ref="529291232"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">186</int> + <reference key="object" ref="272247480"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="396836830"/> + </object> + <reference key="parent" ref="1015660087"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">187</int> + <reference key="object" ref="396836830"/> + <reference key="parent" ref="272247480"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">160</int> + <reference key="object" ref="545855108"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="1052876110"/> + </object> + <reference key="parent" ref="1015660087"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">165</int> + <reference key="object" ref="1052876110"/> + <reference key="parent" ref="545855108"/> + </object> </object> </object> <object class="NSMutableDictionary" key="flattenedProperties"> @@ -509,6 +1048,27 @@ <string>144.IBPluginDependency</string> <string>15.CustomClassName</string> <string>15.IBPluginDependency</string> + <string>156.IBEditorWindowLastContentRect</string> + <string>156.IBPluginDependency</string> + <string>157.IBEditorWindowLastContentRect</string> + <string>157.IBPluginDependency</string> + <string>159.IBPluginDependency</string> + <string>160.IBPluginDependency</string> + <string>161.IBPluginDependency</string> + <string>162.IBPluginDependency</string> + <string>163.IBPluginDependency</string> + <string>164.IBPluginDependency</string> + <string>165.IBPluginDependency</string> + <string>166.IBPluginDependency</string> + <string>168.IBPluginDependency</string> + <string>169.IBPluginDependency</string> + <string>170.IBNSSegmentedControlInspectorSelectedSegmentMetadataKey</string> + <string>170.IBPluginDependency</string> + <string>170.IBSegmentedControlInspectorSelectedSegmentMetadataKey</string> + <string>171.IBPluginDependency</string> + <string>186.IBPluginDependency</string> + <string>187.IBPluginDependency</string> + <string>189.IBPluginDependency</string> <string>2.CustomClassName</string> <string>2.IBAttributePlaceholdersKey</string> <string>2.IBPluginDependency</string> @@ -549,6 +1109,27 @@ <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>ClickHoldButtonCell</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>{{654, 766}, {275, 20}}</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>{{646, 925}, {275, 20}}</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <integer value="0"/> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <integer value="0"/> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>DelayedMenuButton</string> <object class="NSMutableDictionary"> <string key="NS.key.0">ToolTip</string> @@ -622,7 +1203,7 @@ </object> </object> <nil key="sourceID"/> - <int key="maxID">155</int> + <int key="maxID">210</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> @@ -732,6 +1313,29 @@ </object> </object> <object class="IBPartialClassDescription"> + <string key="className">GTMWidthBasedTweaker</string> + <string key="superclassName">NSView</string> + <object class="NSMutableDictionary" key="outlets"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSArray" key="dict.sortedKeys"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>viewToResize_</string> + <string>viewToSlideAndResize_</string> + <string>viewToSlide_</string> + </object> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>id</string> + <string>NSView</string> + <string>NSView</string> + </object> + </object> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBProjectSource</string> + <string key="minorKey">../third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> <string key="className">GradientButtonCell</string> <string key="superclassName">NSButtonCell</string> <object class="IBClassDescriptionSource" key="sourceIdentifier"> @@ -752,6 +1356,14 @@ </object> </object> <object class="IBPartialClassDescription"> + <string key="className">MenuController</string> + <string key="superclassName">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBProjectSource</string> + <string key="minorKey">browser/cocoa/menu_controller.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> <string key="className">NSObject</string> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBProjectSource</string> @@ -818,6 +1430,7 @@ <string>reloadButton_</string> <string>resizeDelegate_</string> <string>wrenchButton_</string> + <string>wrenchMenuController_</string> </object> <object class="NSMutableArray" key="dict.values"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -829,6 +1442,7 @@ <string>ReloadButton</string> <string>id</string> <string>MenuButton</string> + <string>WrenchMenuController</string> </object> </object> <object class="IBClassDescriptionSource" key="sourceIdentifier"> @@ -852,6 +1466,41 @@ <string key="minorKey"/> </object> </object> + <object class="IBPartialClassDescription"> + <string key="className">WrenchMenuController</string> + <string key="superclassName">MenuController</string> + <object class="NSMutableDictionary" key="actions"> + <string key="NS.key.0">dispatchWrenchMenuCommand:</string> + <string key="NS.object.0">id</string> + </object> + <object class="NSMutableDictionary" key="outlets"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="NSArray" key="dict.sortedKeys"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>editControl_</string> + <string>editItem_</string> + <string>zoomDisplay_</string> + <string>zoomFullScreen_</string> + <string>zoomItem_</string> + <string>zoomMinus_</string> + <string>zoomPlus_</string> + </object> + <object class="NSMutableArray" key="dict.values"> + <bool key="EncodedWithXMLCoder">YES</bool> + <string>NSSegmentedControl</string> + <string>NSView</string> + <string>NSButton</string> + <string>NSButton</string> + <string>NSView</string> + <string>NSButton</string> + <string>NSButton</string> + </object> + </object> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBProjectSource</string> + <string key="minorKey">browser/cocoa/wrench_menu_controller.h</string> + </object> + </object> </object> <object class="NSMutableArray" key="referencedPartialClassDescriptionsV3.2+"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -1446,6 +2095,22 @@ </object> </object> <object class="IBPartialClassDescription"> + <string key="className">NSSegmentedCell</string> + <string key="superclassName">NSActionCell</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSSegmentedCell.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSSegmentedControl</string> + <string key="superclassName">NSControl</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSSegmentedControl.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> <string key="className">NSTextField</string> <string key="superclassName">NSControl</string> <object class="IBClassDescriptionSource" key="sourceIdentifier"> @@ -1531,6 +2196,9 @@ <object class="NSArray" key="dict.sortedKeys"> <bool key="EncodedWithXMLCoder">YES</bool> <string>NSActionTemplate</string> + <string>NSAddTemplate</string> + <string>NSEnterFullScreenTemplate</string> + <string>NSRemoveTemplate</string> <string>back_Template</string> <string>forward_Template</string> <string>home_Template</string> @@ -1539,6 +2207,9 @@ <object class="NSMutableArray" key="dict.values"> <bool key="EncodedWithXMLCoder">YES</bool> <string>{15, 15}</string> + <string>{8, 8}</string> + <string>{16, 15}</string> + <string>{8, 8}</string> <string>{19, 19}</string> <string>{19, 19}</string> <string>{19, 19}</string> diff --git a/chrome/browser/cocoa/menu_controller.h b/chrome/browser/cocoa/menu_controller.h index 9c3282c..d14d62b 100644 --- a/chrome/browser/cocoa/menu_controller.h +++ b/chrome/browser/cocoa/menu_controller.h @@ -21,11 +21,22 @@ class MenuModel; // that particular item. It is important that the model outlives this object // as it only maintains weak references. @interface MenuController : NSObject { - @private + @protected + menus::MenuModel* model_; // weak scoped_nsobject<NSMenu> menu_; BOOL useWithPopUpButtonCell_; // If YES, 0th item is blank } +@property (nonatomic, assign) menus::MenuModel* model; +// Note that changing this will have no effect if you use +// |-initWithModel:useWithPopUpButtonCell:| or after the first call to |-menu|. +@property (nonatomic) BOOL useWithPopUpButtonCell; + +// NIB-based initializer. This does not create a menu. Clients can set the +// properties of the object and the menu will be created upon the first call to +// |-menu|. Note that the menu will be immutable after creation. +- (id)init; + // Builds a NSMenu from the pre-built model (must not be nil). Changes made // to the contents of the model after calling this will not be noticed. If // the menu will be displayed by a NSPopUpButtonCell, it needs to be of a @@ -34,14 +45,23 @@ class MenuModel; - (id)initWithModel:(menus::MenuModel*)model useWithPopUpButtonCell:(BOOL)useWithCell; -// Access to the constructed menu. +// Access to the constructed menu if the complex initializer was used. If the +// default initializer was used, then this will create the menu on first call. - (NSMenu*)menu; @end // Exposed only for unit testing, do not call directly. -@interface MenuController(PrivateExposedForTesting) +@interface MenuController (PrivateExposedForTesting) - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item; @end +// Protected methods that subclassers can override. +@interface MenuController (Protected) +- (void)addItemToMenu:(NSMenu*)menu + atIndex:(NSInteger)index + fromModel:(menus::MenuModel*)model + modelIndex:(int)modelIndex; +@end + #endif // CHROME_BROWSER_COCOA_MENU_CONTROLLER_H_ diff --git a/chrome/browser/cocoa/menu_controller.mm b/chrome/browser/cocoa/menu_controller.mm index a34469e..047c8dd 100644 --- a/chrome/browser/cocoa/menu_controller.mm +++ b/chrome/browser/cocoa/menu_controller.mm @@ -10,35 +10,37 @@ #include "base/logging.h" #include "base/sys_string_conversions.h" -@interface MenuController(Private) +@interface MenuController (Private) - (NSMenu*)menuFromModel:(menus::MenuModel*)model; - (void)addSeparatorToMenu:(NSMenu*)menu atIndex:(int)index; -- (void)addItemToMenu:(NSMenu*)menu - atIndex:(int)index - fromModel:(menus::MenuModel*)model - modelIndex:(int)modelIndex; @end @implementation MenuController +@synthesize model = model_; +@synthesize useWithPopUpButtonCell = useWithPopUpButtonCell_; + +- (id)init { + self = [super init]; + return self; +} + - (id)initWithModel:(menus::MenuModel*)model useWithPopUpButtonCell:(BOOL)useWithCell { if ((self = [super init])) { - menu_.reset([[self menuFromModel:model] retain]); - // If this is to be used with a NSPopUpButtonCell, add an item at the 0th - // position that's empty. Doing it after the menu has been constructed won't - // complicate creation logic, and since the tags are model indexes, they - // are unaffected by the extra item. - if (useWithCell) { - scoped_nsobject<NSMenuItem> blankItem( - [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]); - [menu_ insertItem:blankItem atIndex:0]; - } + model_ = model; + useWithPopUpButtonCell_ = useWithCell; + [self menu]; } return self; } +- (void)dealloc { + model_ = NULL; + [super dealloc]; +} + // Creates a NSMenu from the given model. If the model has submenus, this can // be invoked recursively. - (NSMenu*)menuFromModel:(menus::MenuModel*)model { @@ -75,7 +77,7 @@ // Adds an item or a hierarchical menu to the item at the |index|, // associated with the entry in the model indentifed by |modelIndex|. - (void)addItemToMenu:(NSMenu*)menu - atIndex:(int)index + atIndex:(NSInteger)index fromModel:(menus::MenuModel*)model modelIndex:(int)modelIndex { NSString* label = @@ -152,6 +154,18 @@ } - (NSMenu*)menu { + if (!menu_ && model_) { + menu_.reset([[self menuFromModel:model_] retain]); + // If this is to be used with a NSPopUpButtonCell, add an item at the 0th + // position that's empty. Doing it after the menu has been constructed won't + // complicate creation logic, and since the tags are model indexes, they + // are unaffected by the extra item. + if (useWithPopUpButtonCell_) { + scoped_nsobject<NSMenuItem> blankItem( + [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]); + [menu_ insertItem:blankItem atIndex:0]; + } + } return menu_.get(); } diff --git a/chrome/browser/cocoa/menu_controller_unittest.mm b/chrome/browser/cocoa/menu_controller_unittest.mm index f41ef42..de0362a 100644 --- a/chrome/browser/cocoa/menu_controller_unittest.mm +++ b/chrome/browser/cocoa/menu_controller_unittest.mm @@ -175,3 +175,23 @@ TEST_F(MenuControllerTest, Validate) { Validate(menu.get(), [menu menu]); } + +TEST_F(MenuControllerTest, DefaultInitializer) { + Delegate delegate; + menus::SimpleMenuModel model(&delegate); + model.AddItem(1, WideToUTF16(L"one")); + model.AddItem(2, WideToUTF16(L"two")); + model.AddItem(3, WideToUTF16(L"three")); + + scoped_nsobject<MenuController> menu([[MenuController alloc] init]); + EXPECT_FALSE([menu menu]); + + [menu setModel:&model]; + [menu setUseWithPopUpButtonCell:NO]; + EXPECT_TRUE([menu menu]); + EXPECT_EQ(3, [[menu menu] numberOfItems]); + + // Check immutability. + model.AddItem(4, WideToUTF16(L"four")); + EXPECT_EQ(3, [[menu menu] numberOfItems]); +} diff --git a/chrome/browser/cocoa/toolbar_controller.h b/chrome/browser/cocoa/toolbar_controller.h index 2b40d45..9d3ad48 100644 --- a/chrome/browser/cocoa/toolbar_controller.h +++ b/chrome/browser/cocoa/toolbar_controller.h @@ -26,7 +26,6 @@ class CommandUpdater; class LocationBar; class LocationBarViewMac; @class MenuButton; -@class MenuController; namespace ToolbarControllerInternal { class MenuDelegate; class PrefObserverBridge; @@ -35,6 +34,7 @@ class Profile; @class ReloadButton; class TabContents; class ToolbarModel; +@class WrenchMenuController; class WrenchMenuModel; // A controller for the toolbar in the browser window. Manages @@ -55,6 +55,7 @@ class WrenchMenuModel; IBOutlet MenuButton* wrenchButton_; IBOutlet AutocompleteTextField* locationBar_; IBOutlet BrowserActionsContainerView* browserActionsContainerView_; + IBOutlet WrenchMenuController* wrenchMenuController_; @private ToolbarModel* toolbarModel_; // weak, one per window @@ -69,12 +70,11 @@ class WrenchMenuModel; scoped_nsobject<BackForwardMenuController> forwardMenuController_; scoped_nsobject<BrowserActionsController> browserActionsController_; - // Lazily-instantiated model, controller, and delegate for the menu on the + // Lazily-instantiated model and delegate for the menu on the // wrench button. Once visible, it will be non-null, but will not // reaped when the menu is hidden once it is initially shown. scoped_ptr<ToolbarControllerInternal::MenuDelegate> menuDelegate_; scoped_ptr<WrenchMenuModel> wrenchMenuModel_; - scoped_nsobject<MenuController> wrenchMenuController_; // Used for monitoring the optional toolbar button prefs. scoped_ptr<ToolbarControllerInternal::PrefObserverBridge> prefObserver_; @@ -157,6 +157,7 @@ class WrenchMenuModel; // Return the BrowserActionsController for this toolbar. - (BrowserActionsController*)browserActionsController; + @end // A set of private methods used by subclasses. Do not call these directly @@ -178,6 +179,7 @@ class WrenchMenuModel; - (NSArray*)toolbarViews; - (void)showOptionalHomeButton; - (void)installWrenchMenu; +- (WrenchMenuController*)wrenchMenuController; // Return a hover button for the current event. - (NSButton*)hoverButtonForEvent:(NSEvent*)theEvent; @end diff --git a/chrome/browser/cocoa/toolbar_controller.mm b/chrome/browser/cocoa/toolbar_controller.mm index 1a3bc74..dab9537 100644 --- a/chrome/browser/cocoa/toolbar_controller.mm +++ b/chrome/browser/cocoa/toolbar_controller.mm @@ -8,6 +8,7 @@ #include "app/l10n_util_mac.h" #include "app/menus/accelerator_cocoa.h" +#include "app/menus/menu_model.h" #include "base/keyboard_codes.h" #include "base/mac_util.h" #include "base/nsimage_cache_mac.h" @@ -31,6 +32,7 @@ #import "chrome/browser/cocoa/menu_controller.h" #import "chrome/browser/cocoa/reload_button.h" #import "chrome/browser/cocoa/toolbar_view.h" +#import "chrome/browser/cocoa/wrench_menu_controller.h" #include "chrome/browser/net/url_fixer_upper.h" #include "chrome/browser/pref_service.h" #include "chrome/browser/profile.h" @@ -511,12 +513,15 @@ class PrefObserverBridge : public NotificationObserver { menuDelegate_.reset(new ToolbarControllerInternal::MenuDelegate(browser_)); wrenchMenuModel_.reset(new WrenchMenuModel(menuDelegate_.get(), browser_)); - wrenchMenuController_.reset( - [[MenuController alloc] initWithModel:wrenchMenuModel_.get() - useWithPopUpButtonCell:YES]); + [wrenchMenuController_ setModel:wrenchMenuModel_.get()]; + [wrenchMenuController_ setUseWithPopUpButtonCell:YES]; [wrenchButton_ setAttachedMenu:[wrenchMenuController_ menu]]; } +- (WrenchMenuController*)wrenchMenuController { + return wrenchMenuController_; +} + - (void)prefChanged:(std::wstring*)prefName { if (!prefName) return; if (*prefName == prefs::kShowHomeButton) { diff --git a/chrome/browser/cocoa/wrench_menu_controller.h b/chrome/browser/cocoa/wrench_menu_controller.h new file mode 100644 index 0000000..6ec1f55 --- /dev/null +++ b/chrome/browser/cocoa/wrench_menu_controller.h @@ -0,0 +1,46 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_COCOA_WRENCH_MENU_CONTROLLER_H_ +#define CHROME_BROWSER_COCOA_WRENCH_MENU_CONTROLLER_H_ + +#import <Cocoa/Cocoa.h> + +#import "base/cocoa_protocols_mac.h" +#import "chrome/browser/cocoa/menu_controller.h" + +@class ToolbarController; +class WrenchMenuModel; + +// The Wrench menu has a creative layout, with buttons in menu items. There is +// a cross-platform model for this special menu, but on the Mac it's easier to +// get spacing and alignment precisely right using a NIB. To do that, we +// subclass the generic MenuController implementation and special-case the two +// items that require specific layout and load them from the NIB. +// +// This object is instantiated in Toolbar.xib and is configured by the +// ToolbarController. +@interface WrenchMenuController : MenuController <NSMenuDelegate> { + IBOutlet NSView* editItem_; + IBOutlet NSSegmentedControl* editControl_; + + IBOutlet NSView* zoomItem_; + IBOutlet NSButton* zoomPlus_; + IBOutlet NSButton* zoomDisplay_; + IBOutlet NSButton* zoomMinus_; + IBOutlet NSButton* zoomFullScreen_; +} + +// Designated initializer; called within the NIB. +- (id)init; + +// Used to dispatch commands from the Wrench menu. The custom items within the +// menu cannot be hooked up directly to First Responder because the window in +// which the controls reside is not the BrowserWindowController, but a +// NSCarbonMenuWindow; this screws up the typical |-commandDispatch:| system. +- (IBAction)dispatchWrenchMenuCommand:(id)sender; + +@end + +#endif // CHROME_BROWSER_COCOA_WRENCH_MENU_CONTROLLER_H_ diff --git a/chrome/browser/cocoa/wrench_menu_controller.mm b/chrome/browser/cocoa/wrench_menu_controller.mm new file mode 100644 index 0000000..0f31548 --- /dev/null +++ b/chrome/browser/cocoa/wrench_menu_controller.mm @@ -0,0 +1,127 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import "chrome/browser/cocoa/wrench_menu_controller.h" + +#include "app/menus/menu_model.h" +#include "base/sys_string_conversions.h" +#include "chrome/app/chrome_dll_resource.h" +#import "chrome/browser/cocoa/toolbar_controller.h" +#include "chrome/browser/wrench_menu_model.h" + +@interface WrenchMenuController (Private) +- (WrenchMenuModel*)wrenchMenuModel; +- (void)adjustPositioning; +@end + +@implementation WrenchMenuController + +- (id)init { + self = [super init]; + return self; +} + +- (void)addItemToMenu:(NSMenu*)menu + atIndex:(NSInteger)index + fromModel:(menus::MenuModel*)model + modelIndex:(int)modelIndex { + // Non-button item types should be built as normal items. + menus::MenuModel::ItemType type = model->GetTypeAt(modelIndex); + if (type != menus::MenuModel::TYPE_BUTTON_ITEM) { + [super addItemToMenu:menu + atIndex:index + fromModel:model + modelIndex:modelIndex]; + return; + } + + // Handle the special-cased menu items. + int command_id = model->GetCommandIdAt(modelIndex); + scoped_nsobject<NSMenuItem> customItem( + [[NSMenuItem alloc] initWithTitle:@"" + action:nil + keyEquivalent:@""]); + switch (command_id) { + case IDC_EDIT_MENU: + DCHECK(editItem_); + [customItem setView:editItem_]; + break; + case IDC_ZOOM_MENU: + DCHECK(zoomItem_); + [customItem setView:zoomItem_]; + break; + default: + NOTREACHED(); + break; + } + [self adjustPositioning]; + [menu insertItem:customItem.get() atIndex:index]; +} + +- (NSMenu*)menu { + NSMenu* menu = [super menu]; + if (![menu delegate]) { + [menu setDelegate:self]; + } + return menu; +} + +- (void)menuWillOpen:(NSMenu*)menu { + NSString* title = base::SysUTF16ToNSString( + [self wrenchMenuModel]->GetLabelForCommandId(IDC_ZOOM_PERCENT_DISPLAY)); + [[zoomItem_ viewWithTag:IDC_ZOOM_PERCENT_DISPLAY] setTitle:title]; +} + +// Used to dispatch commands from the Wrench menu. The custom items within the +// menu cannot be hooked up directly to First Responder because the window in +// which the controls reside is not the BrowserWindowController, but a +// NSCarbonMenuWindow; this screws up the typical |-commandDispatch:| system. +- (IBAction)dispatchWrenchMenuCommand:(id)sender { + NSInteger tag = [sender tag]; + + // NSSegmentedControls (used for the Edit item) need a little help to get the + // command_id of the pressed item. + if ([sender isKindOfClass:[NSSegmentedControl class]]) + tag = [[sender cell] tagForSegment:[sender selectedSegment]]; + + // The custom views within the Wrench menu are abnormal and keep the menu open + // after a target-action. Close the menu manually. + // TODO(rsesek): It'd be great if the zoom buttons didn't have to close the + // menu. See http://crbug.com/48679 for more info. + [menu_ cancelTracking]; + [self wrenchMenuModel]->ExecuteCommand(tag); +} + +- (WrenchMenuModel*)wrenchMenuModel { + return static_cast<WrenchMenuModel*>(model_); +} + +// Fit the localized strings into the Cut/Copy/Paste control, then resize the +// whole menu item accordingly. +- (void)adjustPositioning { + NSRect itemFrame = [editItem_ frame]; + NSRect controlFrame = [editControl_ frame]; + + CGFloat originalControlWidth = NSWidth(controlFrame); + // Maintain the carefully pixel-pushed gap between the edge of the menu and + // the rightmost control. + CGFloat edge = NSWidth(itemFrame) - + (controlFrame.origin.x + originalControlWidth); + + // Resize the edit segmented control to fit the localized strings. + [editControl_ sizeToFit]; + controlFrame = [editControl_ frame]; + CGFloat resizeAmount = NSWidth(controlFrame) - originalControlWidth; + + // Adjust the size of the entire menu item to account for changes in the size + // of the segmented control. + itemFrame.size.width += resizeAmount; + [editItem_ setFrame:itemFrame]; + + // Keep the spacing between the right edges of the menu and the control. + controlFrame.origin.x = NSWidth(itemFrame) - edge - NSWidth(controlFrame); + [editControl_ setFrame:controlFrame]; +} + +@end // @implementation WrenchMenuController diff --git a/chrome/browser/cocoa/wrench_menu_controller_unittest.mm b/chrome/browser/cocoa/wrench_menu_controller_unittest.mm new file mode 100644 index 0000000..6eafe33 --- /dev/null +++ b/chrome/browser/cocoa/wrench_menu_controller_unittest.mm @@ -0,0 +1,81 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/scoped_nsobject.h" +#include "chrome/app/chrome_dll_resource.h" +#include "chrome/browser/cocoa/browser_test_helper.h" +#import "chrome/browser/cocoa/cocoa_test_helper.h" +#import "chrome/browser/cocoa/toolbar_controller.h" +#import "chrome/browser/cocoa/wrench_menu_controller.h" +#import "chrome/browser/cocoa/view_resizer_pong.h" +#include "chrome/browser/wrench_menu_model.h" +#include "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "testing/platform_test.h" + +namespace { + +class MockWrenchMenuModel : public WrenchMenuModel { + public: + MockWrenchMenuModel() : WrenchMenuModel() {} + MOCK_METHOD1(ExecuteCommand, void(int command_id)); +}; + +class WrenchMenuControllerTest : public CocoaTest { + public: + void SetUp() { + Browser* browser = helper_.browser(); + resize_delegate_.reset([[ViewResizerPong alloc] init]); + toolbar_controller_.reset( + [[ToolbarController alloc] initWithModel:browser->toolbar_model() + commands:browser->command_updater() + profile:helper_.profile() + browser:browser + resizeDelegate:resize_delegate_.get()]); + EXPECT_TRUE([toolbar_controller_ view]); + NSView* parent = [test_window() contentView]; + [parent addSubview:[toolbar_controller_ view]]; + } + + WrenchMenuController* controller() { + return [toolbar_controller_ wrenchMenuController]; + } + + BrowserTestHelper helper_; + scoped_nsobject<ViewResizerPong> resize_delegate_; + MockWrenchMenuModel fake_model_; + scoped_nsobject<ToolbarController> toolbar_controller_; +}; + +TEST_F(WrenchMenuControllerTest, Initialized) { + EXPECT_TRUE([controller() menu]); + EXPECT_GE([[controller() menu] numberOfItems], 5); +} + +TEST_F(WrenchMenuControllerTest, DispatchSimple) { + scoped_nsobject<NSButton> button([[NSButton alloc] init]); + [button setTag:IDC_ZOOM_PLUS]; + + // Set fake model to test dispatching. + EXPECT_CALL(fake_model_, ExecuteCommand(IDC_ZOOM_PLUS)); + [controller() setModel:&fake_model_]; + + [controller() dispatchWrenchMenuCommand:button.get()]; +} + +TEST_F(WrenchMenuControllerTest, DispatchSegmentedControl) { + // Set fake model to test dispatching. + EXPECT_CALL(fake_model_, ExecuteCommand(IDC_CUT)); + [controller() setModel:&fake_model_]; + + scoped_nsobject<NSSegmentedControl> control( + [[NSSegmentedControl alloc] init]); + [control setSegmentCount:2]; + [[control cell] setTag:IDC_CUT forSegment:0]; + [[control cell] setSelectedSegment:0]; + + [controller() dispatchWrenchMenuCommand:control.get()]; +} + +} // namespace diff --git a/chrome/browser/wrench_menu_model.cc b/chrome/browser/wrench_menu_model.cc index 2531280..dde128c 100644 --- a/chrome/browser/wrench_menu_model.cc +++ b/chrome/browser/wrench_menu_model.cc @@ -200,19 +200,23 @@ void WrenchMenuModel::Build() { AddItemWithStringId(IDC_NEW_INCOGNITO_WINDOW, IDS_NEW_INCOGNITO_WINDOW); AddSeparator(); -#if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS) +#if defined(OS_MACOSX) || (defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)) + // WARNING: Mac does not use the ButtonMenuItemModel, but instead defines the + // layout for this menu item in Toolbar.xib. It does, however, use the + // command_id value from AddButtonItem() to identify this special item. edit_menu_item_model_.reset(new menus::ButtonMenuItemModel(IDS_EDIT, this)); edit_menu_item_model_->AddGroupItemWithStringId(IDC_CUT, IDS_CUT); edit_menu_item_model_->AddGroupItemWithStringId(IDC_COPY, IDS_COPY); edit_menu_item_model_->AddGroupItemWithStringId(IDC_PASTE, IDS_PASTE); - AddButtonItem(0, edit_menu_item_model_.get()); + AddButtonItem(IDC_EDIT_MENU, edit_menu_item_model_.get()); #else // TODO(port): Move to the above. CreateCutCopyPaste(); #endif AddSeparator(); -#if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS) +#if defined(OS_MACOSX) || (defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)) + // WARNING: See above comment. zoom_menu_item_model_.reset( new menus::ButtonMenuItemModel(IDS_ZOOM_MENU, this)); zoom_menu_item_model_->AddGroupItemWithStringId( @@ -224,7 +228,7 @@ void WrenchMenuModel::Build() { zoom_menu_item_model_->AddSpace(); zoom_menu_item_model_->AddItemWithImage( IDC_FULLSCREEN, IDR_FULLSCREEN_MENU_BUTTON); - AddButtonItem(0, zoom_menu_item_model_.get()); + AddButtonItem(IDC_ZOOM_MENU, zoom_menu_item_model_.get()); #else // TODO(port): Move to the above. CreateZoomFullscreen(); diff --git a/chrome/browser/wrench_menu_model.h b/chrome/browser/wrench_menu_model.h index c7f6604..b7dc724 100644 --- a/chrome/browser/wrench_menu_model.h +++ b/chrome/browser/wrench_menu_model.h @@ -23,6 +23,10 @@ namespace menus { class ButtonMenuItemModel; } // namespace menus +namespace { +class MockWrenchMenuModel; +} // namespace + class ToolsMenuModel : public menus::SimpleMenuModel { public: ToolsMenuModel(menus::SimpleMenuModel::Delegate* delegate, Browser* browser); @@ -75,6 +79,10 @@ class WrenchMenuModel : public menus::SimpleMenuModel, const NotificationDetails& details); private: + // Testing constructor used for mocking. + friend class ::MockWrenchMenuModel; + WrenchMenuModel() : menus::SimpleMenuModel(NULL) {} + void Build(); // Adds custom items to the menu. Deprecated in favor of a cross platform diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index c96158d..e20589b 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -987,6 +987,8 @@ 'browser/cocoa/web_drop_target.mm', 'browser/cocoa/window_size_autosaver.h', 'browser/cocoa/window_size_autosaver.mm', + 'browser/cocoa/wrench_menu_controller.h', + 'browser/cocoa/wrench_menu_controller.mm', 'browser/command_updater.cc', 'browser/command_updater.h', 'browser/config_dir_policy_provider.cc', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index c36ad23..630b1d1 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -763,6 +763,7 @@ 'browser/cocoa/view_resizer_pong.mm', 'browser/cocoa/web_drop_target_unittest.mm', 'browser/cocoa/window_size_autosaver_unittest.mm', + 'browser/cocoa/wrench_menu_controller_unittest.mm', 'browser/config_dir_policy_provider_unittest.cc', 'browser/command_updater_unittest.cc', 'browser/configuration_policy_pref_store_unittest.cc', |