diff options
author | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-09 19:56:30 +0000 |
---|---|---|
committer | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-09 19:56:30 +0000 |
commit | 273865aa130f61f321d3eeafc0ea5a2a6dc9adf8 (patch) | |
tree | 05b9f5275ef0a0c63592f9b1102235aead02b59d | |
parent | 12c7b1eaa34937a72c8b81de17fdb5c72d842431 (diff) | |
download | chromium_src-273865aa130f61f321d3eeafc0ea5a2a6dc9adf8.zip chromium_src-273865aa130f61f321d3eeafc0ea5a2a6dc9adf8.tar.gz chromium_src-273865aa130f61f321d3eeafc0ea5a2a6dc9adf8.tar.bz2 |
Share the code that builds the page menu in a common model, make Mac and Win use it. Implement a mac menu controller that takes this model and generates an NSMenu. Remove the Page Menu NSMenu from Toolbar.xib since it's now created in code.
BUG=22646
TEST=page menu should work as before
Review URL: http://codereview.chromium.org/465130
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34179 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | app/menus/simple_menu_model.h | 2 | ||||
-rw-r--r-- | chrome/app/nibs/Toolbar.xib | 710 | ||||
-rw-r--r-- | chrome/browser/cocoa/menu_controller.h | 49 | ||||
-rw-r--r-- | chrome/browser/cocoa/menu_controller.mm | 145 | ||||
-rw-r--r-- | chrome/browser/cocoa/menu_controller_unittest.mm | 177 | ||||
-rw-r--r-- | chrome/browser/cocoa/toolbar_controller.h | 11 | ||||
-rw-r--r-- | chrome/browser/cocoa/toolbar_controller.mm | 54 | ||||
-rw-r--r-- | chrome/browser/cocoa/toolbar_controller_unittest.mm | 11 | ||||
-rw-r--r-- | chrome/browser/page_menu_model.cc | 138 | ||||
-rw-r--r-- | chrome/browser/page_menu_model.h | 82 | ||||
-rw-r--r-- | chrome/browser/page_menu_model_unittest.cc | 63 | ||||
-rw-r--r-- | chrome/browser/views/toolbar_view.cc | 131 | ||||
-rw-r--r-- | chrome/browser/views/toolbar_view.h | 45 | ||||
-rwxr-xr-x | chrome/chrome_browser.gypi | 4 | ||||
-rwxr-xr-x | chrome/chrome_tests.gypi | 2 |
15 files changed, 782 insertions, 842 deletions
diff --git a/app/menus/simple_menu_model.h b/app/menus/simple_menu_model.h index 7d73703..e093bb2 100644 --- a/app/menus/simple_menu_model.h +++ b/app/menus/simple_menu_model.h @@ -87,6 +87,8 @@ class SimpleMenuModel : public MenuModel { // returns what it's passed. virtual int FlipIndex(int index) const { return index; } + Delegate* delegate() { return delegate_; } + private: struct Item { int command_id; diff --git a/chrome/app/nibs/Toolbar.xib b/chrome/app/nibs/Toolbar.xib index 9363025..b4aed92 100644 --- a/chrome/app/nibs/Toolbar.xib +++ b/chrome/app/nibs/Toolbar.xib @@ -8,9 +8,6 @@ <string key="IBDocument.HIToolboxVersion">353.00</string> <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> <bool key="EncodedWithXMLCoder">YES</bool> - <integer value="1"/> - <integer value="42"/> - <integer value="48"/> </object> <object class="NSArray" key="IBDocument.PluginDependencies"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -46,6 +43,7 @@ <int key="NSvFlags">265</int> <string key="NSFrame">{{540, 0}, {0.777771, 36}}</string> <reference key="NSSuperview" ref="928520650"/> + <reference key="NSWindow"/> <string key="NSClassName">NSView</string> </object> <object class="NSTextField" id="535508469"> @@ -53,6 +51,7 @@ <int key="NSvFlags">266</int> <string key="NSFrame">{{165, 5}, {341, 27}}</string> <reference key="NSSuperview" ref="928520650"/> + <reference key="NSWindow"/> <int key="NSTag">33004</int> <bool key="NSEnabled">YES</bool> <object class="NSTextFieldCell" key="NSCell" id="464583340"> @@ -91,6 +90,7 @@ <int key="NSvFlags">268</int> <string key="NSFrame">{{101, 5}, {31, 27}}</string> <reference key="NSSuperview" ref="928520650"/> + <reference key="NSWindow"/> <int key="NSTag">33003</int> <bool key="NSEnabled">YES</bool> <object class="NSButtonCell" key="NSCell" id="760046712"> @@ -120,6 +120,7 @@ <int key="NSvFlags">268</int> <string key="NSFrame">{{136, 5}, {29, 27}}</string> <reference key="NSSuperview" ref="928520650"/> + <reference key="NSWindow"/> <int key="NSTag">35000</int> <bool key="NSEnabled">YES</bool> <object class="NSButtonCell" key="NSCell" id="960568152"> @@ -150,6 +151,7 @@ <int key="NSvFlags">268</int> <string key="NSFrame">{{66, 5}, {31, 27}}</string> <reference key="NSSuperview" ref="928520650"/> + <reference key="NSWindow"/> <int key="NSTag">33002</int> <bool key="NSEnabled">YES</bool> <object class="NSButtonCell" key="NSCell" id="386107000"> @@ -175,6 +177,7 @@ <int key="NSvFlags">268</int> <string key="NSFrame">{{34, 5}, {28, 27}}</string> <reference key="NSSuperview" ref="928520650"/> + <reference key="NSWindow"/> <int key="NSTag">33001</int> <bool key="NSEnabled">YES</bool> <object class="NSButtonCell" key="NSCell" id="3781855"> @@ -201,6 +204,7 @@ <int key="NSvFlags">268</int> <string key="NSFrame">{{5, 5}, {29, 27}}</string> <reference key="NSSuperview" ref="928520650"/> + <reference key="NSWindow"/> <int key="NSTag">33000</int> <bool key="NSEnabled">YES</bool> <object class="NSButtonCell" key="NSCell" id="697431051"> @@ -227,6 +231,7 @@ <int key="NSvFlags">265</int> <string key="NSFrame">{{506, 5}, {29, 27}}</string> <reference key="NSSuperview" ref="928520650"/> + <reference key="NSWindow"/> <int key="NSTag">33005</int> <bool key="NSEnabled">YES</bool> <object class="NSButtonCell" key="NSCell" id="203834804"> @@ -253,6 +258,7 @@ <int key="NSvFlags">265</int> <string key="NSFrame">{{540, 5}, {35, 27}}</string> <reference key="NSSuperview" ref="928520650"/> + <reference key="NSWindow"/> <int key="NSTag">33005</int> <bool key="NSEnabled">YES</bool> <object class="NSButtonCell" key="NSCell" id="482050975"> @@ -278,6 +284,7 @@ <int key="NSvFlags">265</int> <string key="NSFrame">{{574, 5}, {35, 27}}</string> <reference key="NSSuperview" ref="928520650"/> + <reference key="NSWindow"/> <int key="NSTag">33005</int> <bool key="NSEnabled">YES</bool> <object class="NSButtonCell" key="NSCell" id="204555298"> @@ -301,263 +308,34 @@ </object> <string key="NSFrameSize">{618, 36}</string> <reference key="NSSuperview"/> + <reference key="NSWindow"/> <string key="NSClassName">ToolbarView</string> </object> - <object class="NSMenu" id="1035953805"> - <string key="NSTitle">Page Menu</string> + <object class="NSMenu" id="558188039"> + <string key="NSTitle">Wrench Menu</string> <object class="NSMutableArray" key="NSMenuItems"> <bool key="EncodedWithXMLCoder">YES</bool> - <object class="NSMenuItem" id="633871226"> - <reference key="NSMenu" ref="1035953805"/> + <object class="NSMenuItem" id="306298564"> + <reference key="NSMenu" ref="558188039"/> <string key="NSTitle"/> <string key="NSKeyEquiv"/> <int key="NSMnemonicLoc">2147483647</int> - <object class="NSCustomResource" key="NSOnImage" id="610745052"> + <object class="NSCustomResource" key="NSOnImage" id="377723476"> <string key="NSClassName">NSImage</string> <string key="NSResourceName">NSMenuCheckmark</string> </object> - <object class="NSCustomResource" key="NSMixedImage" id="1070349142"> + <object class="NSCustomResource" key="NSMixedImage" id="651760058"> <string key="NSClassName">NSImage</string> <string key="NSResourceName">NSMenuMixedState</string> </object> </object> - <object class="NSMenuItem" id="531344134"> - <reference key="NSMenu" ref="1035953805"/> - <string key="NSTitle">^IDS_CREATE_SHORTCUTS</string> - <string key="NSKeyEquiv"/> - <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> - </object> - <object class="NSMenuItem" id="940961375"> - <reference key="NSMenu" ref="1035953805"/> - <bool key="NSIsDisabled">YES</bool> - <bool key="NSIsSeparator">YES</bool> - <string key="NSTitle"/> - <string key="NSKeyEquiv"/> - <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> - </object> - <object class="NSMenuItem" id="356573692"> - <reference key="NSMenu" ref="1035953805"/> - <string key="NSTitle">^IDS_CUT</string> - <string key="NSKeyEquiv"/> - <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> - </object> - <object class="NSMenuItem" id="525046613"> - <reference key="NSMenu" ref="1035953805"/> - <string key="NSTitle">^IDS_COPY</string> - <string key="NSKeyEquiv"/> - <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> - </object> - <object class="NSMenuItem" id="871702681"> - <reference key="NSMenu" ref="1035953805"/> - <string key="NSTitle">^IDS_PASTE</string> - <string key="NSKeyEquiv"/> - <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> - </object> - <object class="NSMenuItem" id="865353905"> - <reference key="NSMenu" ref="1035953805"/> - <bool key="NSIsDisabled">YES</bool> - <bool key="NSIsSeparator">YES</bool> - <string key="NSTitle"/> - <string key="NSKeyEquiv"/> - <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> - </object> - <object class="NSMenuItem" id="552802748"> - <reference key="NSMenu" ref="1035953805"/> - <string key="NSTitle">^IDS_FIND</string> - <string key="NSKeyEquiv"/> - <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> - <int key="NSTag">37000</int> - </object> - <object class="NSMenuItem" id="759431372"> - <reference key="NSMenu" ref="1035953805"/> - <string key="NSTitle">^IDS_SAVE_PAGE</string> - <string key="NSKeyEquiv"/> - <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> - <int key="NSTag">35005</int> - </object> - <object class="NSMenuItem" id="950677546"> - <reference key="NSMenu" ref="1035953805"/> - <string key="NSTitle">^IDS_PRINT</string> - <string key="NSKeyEquiv"/> - <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> - <int key="NSTag">35004</int> - </object> - <object class="NSMenuItem" id="762740339"> - <reference key="NSMenu" ref="1035953805"/> - <bool key="NSIsDisabled">YES</bool> - <bool key="NSIsSeparator">YES</bool> - <string key="NSTitle"/> - <string key="NSKeyEquiv"/> - <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> - </object> - <object class="NSMenuItem" id="398561686"> - <reference key="NSMenu" ref="1035953805"/> - <string key="NSTitle">^IDS_ZOOM_MENU</string> - <string key="NSKeyEquiv"/> - <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> - <string key="NSAction">submenuAction:</string> - <object class="NSMenu" key="NSSubmenu" id="767450548"> - <string key="NSTitle">^IDS_ZOOM_MENU</string> - <object class="NSMutableArray" key="NSMenuItems"> - <bool key="EncodedWithXMLCoder">YES</bool> - <object class="NSMenuItem" id="117630796"> - <reference key="NSMenu" ref="767450548"/> - <string key="NSTitle">^IDS_ZOOM_PLUS</string> - <string key="NSKeyEquiv"/> - <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> - <int key="NSTag">38001</int> - </object> - <object class="NSMenuItem" id="246635843"> - <reference key="NSMenu" ref="767450548"/> - <string key="NSTitle">^IDS_ZOOM_NORMAL</string> - <string key="NSKeyEquiv"/> - <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> - <int key="NSTag">38002</int> - </object> - <object class="NSMenuItem" id="660549409"> - <reference key="NSMenu" ref="767450548"/> - <string key="NSTitle">^IDS_ZOOM_MINUS</string> - <string key="NSKeyEquiv"/> - <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> - <int key="NSTag">38003</int> - </object> - </object> - </object> - </object> - <object class="NSMenuItem" id="275495410"> - <reference key="NSMenu" ref="1035953805"/> - <string key="NSTitle">^IDS_ENCODING_MENU</string> - <string key="NSKeyEquiv"/> - <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> - <string key="NSAction">submenuAction:</string> - <object class="NSMenu" key="NSSubmenu" id="1054137046"> - <string key="NSTitle">^IDS_ENCODING_MENU</string> - <object class="NSMutableArray" key="NSMenuItems"> - <bool key="EncodedWithXMLCoder">YES</bool> - </object> - </object> - </object> - <object class="NSMenuItem" id="344412831"> - <reference key="NSMenu" ref="1035953805"/> - <bool key="NSIsDisabled">YES</bool> - <bool key="NSIsSeparator">YES</bool> - <string key="NSTitle"/> - <string key="NSKeyEquiv"/> - <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> - </object> - <object class="NSMenuItem" id="448429887"> - <reference key="NSMenu" ref="1035953805"/> - <string key="NSTitle">^IDS_DEVELOPER_MENU</string> - <string key="NSKeyEquiv"/> - <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> - <string key="NSAction">submenuAction:</string> - <object class="NSMenu" key="NSSubmenu" id="383305928"> - <string key="NSTitle">^IDS_DEVELOPER_MENU</string> - <object class="NSMutableArray" key="NSMenuItems"> - <bool key="EncodedWithXMLCoder">YES</bool> - <object class="NSMenuItem" id="688272012"> - <reference key="NSMenu" ref="383305928"/> - <string key="NSTitle">^IDS_VIEW_SOURCE</string> - <string key="NSKeyEquiv"/> - <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> - <int key="NSTag">35002</int> - </object> - <object class="NSMenuItem" id="830865062"> - <reference key="NSMenu" ref="383305928"/> - <string key="NSTitle">^IDS_DEV_TOOLS</string> - <string key="NSKeyEquiv"/> - <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> - <int key="NSTag">40004</int> - </object> - <object class="NSMenuItem" id="712404949"> - <reference key="NSMenu" ref="383305928"/> - <string key="NSTitle">^IDS_TASK_MANAGER</string> - <string key="NSKeyEquiv"/> - <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> - </object> - </object> - </object> - </object> - <object class="NSMenuItem" id="236901479"> - <reference key="NSMenu" ref="1035953805"/> - <bool key="NSIsDisabled">YES</bool> - <bool key="NSIsSeparator">YES</bool> - <string key="NSTitle"/> - <string key="NSKeyEquiv"/> - <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> - </object> - <object class="NSMenuItem" id="966232471"> - <reference key="NSMenu" ref="1035953805"/> - <string key="NSTitle">^IDS_REPORT_BUG</string> - <string key="NSKeyEquiv"/> - <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> - <int key="NSTag">40008</int> - </object> - </object> - </object> - <object class="NSMenu" id="558188039"> - <string key="NSTitle">Wrench Menu</string> - <object class="NSMutableArray" key="NSMenuItems"> - <bool key="EncodedWithXMLCoder">YES</bool> - <object class="NSMenuItem" id="306298564"> - <reference key="NSMenu" ref="558188039"/> - <string key="NSTitle"/> - <string key="NSKeyEquiv"/> - <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> - </object> <object class="NSMenuItem" id="824187729"> <reference key="NSMenu" ref="558188039"/> <string key="NSTitle">^IDS_NEW_TAB</string> <string key="NSKeyEquiv"/> <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> + <reference key="NSOnImage" ref="377723476"/> + <reference key="NSMixedImage" ref="651760058"/> <int key="NSTag">34014</int> </object> <object class="NSMenuItem" id="300890436"> @@ -565,8 +343,8 @@ <string key="NSTitle">^IDS_NEW_WINDOW</string> <string key="NSKeyEquiv"/> <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> + <reference key="NSOnImage" ref="377723476"/> + <reference key="NSMixedImage" ref="651760058"/> <int key="NSTag">34000</int> </object> <object class="NSMenuItem" id="498957868"> @@ -574,8 +352,8 @@ <string key="NSTitle">^IDS_NEW_INCOGNITO_WINDOW</string> <string key="NSKeyEquiv"/> <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> + <reference key="NSOnImage" ref="377723476"/> + <reference key="NSMixedImage" ref="651760058"/> <int key="NSTag">34001</int> </object> <object class="NSMenuItem" id="805002579"> @@ -585,16 +363,16 @@ <string key="NSTitle"/> <string key="NSKeyEquiv"/> <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> + <reference key="NSOnImage" ref="377723476"/> + <reference key="NSMixedImage" ref="651760058"/> </object> <object class="NSMenuItem" id="755764032"> <reference key="NSMenu" ref="558188039"/> <string key="NSTitle">^IDS_BOOMARK_BAR_ALWAYS_SHOW</string> <string key="NSKeyEquiv"/> <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> + <reference key="NSOnImage" ref="377723476"/> + <reference key="NSMixedImage" ref="651760058"/> <int key="NSTag">40009</int> </object> <object class="NSMenuItem" id="1051303932"> @@ -602,8 +380,8 @@ <string key="NSTitle">^IDS_FULLSCREEN</string> <string key="NSKeyEquiv"/> <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> + <reference key="NSOnImage" ref="377723476"/> + <reference key="NSMixedImage" ref="651760058"/> <int key="NSTag">34030</int> </object> <object class="NSMenuItem" id="800541023"> @@ -613,16 +391,16 @@ <string key="NSTitle"/> <string key="NSKeyEquiv"/> <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> + <reference key="NSOnImage" ref="377723476"/> + <reference key="NSMixedImage" ref="651760058"/> </object> <object class="NSMenuItem" id="118179064"> <reference key="NSMenu" ref="558188039"/> <string key="NSTitle">^IDS_CLEAR_BROWSING_DATA_MAC</string> <string key="NSKeyEquiv"/> <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> + <reference key="NSOnImage" ref="377723476"/> + <reference key="NSMixedImage" ref="651760058"/> <int key="NSTag">40013</int> </object> <object class="NSMenuItem" id="791058457"> @@ -630,8 +408,8 @@ <string key="NSTitle">^IDS_IMPORT_SETTINGS_TITLE</string> <string key="NSKeyEquiv"/> <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> + <reference key="NSOnImage" ref="377723476"/> + <reference key="NSMixedImage" ref="651760058"/> <int key="NSTag">40014</int> </object> <object class="NSMenuItem" id="1010888289"> @@ -641,16 +419,16 @@ <string key="NSTitle"/> <string key="NSKeyEquiv"/> <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> + <reference key="NSOnImage" ref="377723476"/> + <reference key="NSMixedImage" ref="651760058"/> </object> <object class="NSMenuItem" id="6307962"> <reference key="NSMenu" ref="558188039"/> <string key="NSTitle">^IDS_SHOW_HISTORY</string> <string key="NSKeyEquiv"/> <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> + <reference key="NSOnImage" ref="377723476"/> + <reference key="NSMixedImage" ref="651760058"/> <int key="NSTag">40010</int> </object> <object class="NSMenuItem" id="241294165"> @@ -658,16 +436,16 @@ <string key="NSTitle">^IDS_BOOKMARK_MANAGER</string> <string key="NSKeyEquiv"/> <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> + <reference key="NSOnImage" ref="377723476"/> + <reference key="NSMixedImage" ref="651760058"/> </object> <object class="NSMenuItem" id="548636593"> <reference key="NSMenu" ref="558188039"/> <string key="NSTitle">^IDS_SHOW_DOWNLOADS</string> <string key="NSKeyEquiv"/> <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> + <reference key="NSOnImage" ref="377723476"/> + <reference key="NSMixedImage" ref="651760058"/> <int key="NSTag">40012</int> </object> <object class="NSMenuItem" id="211303389"> @@ -675,8 +453,8 @@ <string key="NSTitle">^IDS_SHOW_EXTENSIONS</string> <string key="NSKeyEquiv"/> <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> + <reference key="NSOnImage" ref="377723476"/> + <reference key="NSMixedImage" ref="651760058"/> <int key="NSTag">40023</int> </object> <object class="NSMenuItem" id="163898806"> @@ -686,8 +464,8 @@ <string key="NSTitle"/> <string key="NSKeyEquiv"/> <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> + <reference key="NSOnImage" ref="377723476"/> + <reference key="NSMixedImage" ref="651760058"/> </object> <object class="NSMenuItem" id="1012539825"> <reference key="NSMenu" ref="558188039"/> @@ -696,8 +474,8 @@ <string key="NSTitle">^IDS_SYNC_START_SYNC_BUTTON_LABEL</string> <string key="NSKeyEquiv"/> <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> + <reference key="NSOnImage" ref="377723476"/> + <reference key="NSMixedImage" ref="651760058"/> <int key="NSTag">41108</int> </object> <object class="NSMenuItem" id="922630377"> @@ -708,16 +486,16 @@ <string key="NSTitle"/> <string key="NSKeyEquiv"/> <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> + <reference key="NSOnImage" ref="377723476"/> + <reference key="NSMixedImage" ref="651760058"/> </object> <object class="NSMenuItem" id="510846575"> <reference key="NSMenu" ref="558188039"/> <string key="NSTitle">^IDS_PREFERENCES_MAC</string> <string key="NSKeyEquiv"/> <int key="NSMnemonicLoc">2147483647</int> - <reference key="NSOnImage" ref="610745052"/> - <reference key="NSMixedImage" ref="1070349142"/> + <reference key="NSOnImage" ref="377723476"/> + <reference key="NSMixedImage" ref="651760058"/> </object> </object> </object> @@ -847,110 +625,6 @@ <object class="IBActionConnection" key="connection"> <string key="label">commandDispatch:</string> <reference key="source" ref="1003"/> - <reference key="destination" ref="531344134"/> - </object> - <int key="connectionID">71</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBActionConnection" key="connection"> - <string key="label">commandDispatch:</string> - <reference key="source" ref="1003"/> - <reference key="destination" ref="552802748"/> - </object> - <int key="connectionID">75</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBActionConnection" key="connection"> - <string key="label">commandDispatch:</string> - <reference key="source" ref="1003"/> - <reference key="destination" ref="759431372"/> - </object> - <int key="connectionID">76</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBActionConnection" key="connection"> - <string key="label">commandDispatch:</string> - <reference key="source" ref="1003"/> - <reference key="destination" ref="950677546"/> - </object> - <int key="connectionID">77</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBActionConnection" key="connection"> - <string key="label">commandDispatch:</string> - <reference key="source" ref="1003"/> - <reference key="destination" ref="966232471"/> - </object> - <int key="connectionID">78</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBActionConnection" key="connection"> - <string key="label">cut:</string> - <reference key="source" ref="1003"/> - <reference key="destination" ref="356573692"/> - </object> - <int key="connectionID">79</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBActionConnection" key="connection"> - <string key="label">copy:</string> - <reference key="source" ref="1003"/> - <reference key="destination" ref="525046613"/> - </object> - <int key="connectionID">80</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBActionConnection" key="connection"> - <string key="label">paste:</string> - <reference key="source" ref="1003"/> - <reference key="destination" ref="871702681"/> - </object> - <int key="connectionID">81</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBActionConnection" key="connection"> - <string key="label">commandDispatch:</string> - <reference key="source" ref="1003"/> - <reference key="destination" ref="117630796"/> - </object> - <int key="connectionID">84</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBActionConnection" key="connection"> - <string key="label">commandDispatch:</string> - <reference key="source" ref="1003"/> - <reference key="destination" ref="246635843"/> - </object> - <int key="connectionID">85</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBActionConnection" key="connection"> - <string key="label">commandDispatch:</string> - <reference key="source" ref="1003"/> - <reference key="destination" ref="660549409"/> - </object> - <int key="connectionID">86</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBActionConnection" key="connection"> - <string key="label">commandDispatch:</string> - <reference key="source" ref="1003"/> - <reference key="destination" ref="688272012"/> - </object> - <int key="connectionID">93</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBActionConnection" key="connection"> - <string key="label">commandDispatch:</string> - <reference key="source" ref="1003"/> - <reference key="destination" ref="712404949"/> - </object> - <int key="connectionID">95</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBActionConnection" key="connection"> - <string key="label">commandDispatch:</string> - <reference key="source" ref="1003"/> <reference key="destination" ref="824187729"/> </object> <int key="connectionID">108</int> @@ -1045,22 +719,6 @@ </object> <object class="IBConnectionRecord"> <object class="IBOutletConnection" key="connection"> - <string key="label">encodingMenu_</string> - <reference key="source" ref="1001"/> - <reference key="destination" ref="1054137046"/> - </object> - <int key="connectionID">134</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBOutletConnection" key="connection"> - <string key="label">attachedMenu_</string> - <reference key="source" ref="571076484"/> - <reference key="destination" ref="1035953805"/> - </object> - <int key="connectionID">135</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBOutletConnection" key="connection"> <string key="label">attachedMenu_</string> <reference key="source" ref="602421009"/> <reference key="destination" ref="558188039"/> @@ -1069,14 +727,6 @@ </object> <object class="IBConnectionRecord"> <object class="IBActionConnection" key="connection"> - <string key="label">commandDispatch:</string> - <reference key="source" ref="1003"/> - <reference key="destination" ref="830865062"/> - </object> - <int key="connectionID">137</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBActionConnection" key="connection"> <string key="label">commandDispatchUsingKeyModifiers:</string> <reference key="source" ref="1003"/> <reference key="destination" ref="634265909"/> @@ -1092,14 +742,6 @@ <int key="connectionID">139</int> </object> <object class="IBConnectionRecord"> - <object class="IBOutletConnection" key="connection"> - <string key="label">yetAnotherObjectToLocalize_</string> - <reference key="source" ref="1044322163"/> - <reference key="destination" ref="1035953805"/> - </object> - <int key="connectionID">140</int> - </object> - <object class="IBConnectionRecord"> <object class="IBActionConnection" key="connection"> <string key="label">commandDispatch:</string> <reference key="source" ref="1003"/> @@ -1314,46 +956,6 @@ <reference key="parent" ref="602421009"/> </object> <object class="IBObjectRecord"> - <int key="objectID">42</int> - <reference key="object" ref="1035953805"/> - <object class="NSMutableArray" key="children"> - <bool key="EncodedWithXMLCoder">YES</bool> - <reference ref="531344134"/> - <reference ref="356573692"/> - <reference ref="525046613"/> - <reference ref="940961375"/> - <reference ref="871702681"/> - <reference ref="865353905"/> - <reference ref="552802748"/> - <reference ref="950677546"/> - <reference ref="759431372"/> - <reference ref="762740339"/> - <reference ref="398561686"/> - <reference ref="344412831"/> - <reference ref="448429887"/> - <reference ref="275495410"/> - <reference ref="966232471"/> - <reference ref="236901479"/> - <reference ref="633871226"/> - </object> - <reference key="parent" ref="835640952"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">43</int> - <reference key="object" ref="531344134"/> - <reference key="parent" ref="1035953805"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">44</int> - <reference key="object" ref="356573692"/> - <reference key="parent" ref="1035953805"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">45</int> - <reference key="object" ref="525046613"/> - <reference key="parent" ref="1035953805"/> - </object> - <object class="IBObjectRecord"> <int key="objectID">48</int> <reference key="object" ref="558188039"/> <object class="NSMutableArray" key="children"> @@ -1396,143 +998,6 @@ <reference key="parent" ref="558188039"/> </object> <object class="IBObjectRecord"> - <int key="objectID">52</int> - <reference key="object" ref="940961375"/> - <reference key="parent" ref="1035953805"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">53</int> - <reference key="object" ref="871702681"/> - <reference key="parent" ref="1035953805"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">54</int> - <reference key="object" ref="865353905"/> - <reference key="parent" ref="1035953805"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">55</int> - <reference key="object" ref="552802748"/> - <reference key="parent" ref="1035953805"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">56</int> - <reference key="object" ref="950677546"/> - <reference key="parent" ref="1035953805"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">57</int> - <reference key="object" ref="759431372"/> - <reference key="parent" ref="1035953805"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">58</int> - <reference key="object" ref="762740339"/> - <reference key="parent" ref="1035953805"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">59</int> - <reference key="object" ref="398561686"/> - <object class="NSMutableArray" key="children"> - <bool key="EncodedWithXMLCoder">YES</bool> - <reference ref="767450548"/> - </object> - <reference key="parent" ref="1035953805"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">60</int> - <reference key="object" ref="767450548"/> - <object class="NSMutableArray" key="children"> - <bool key="EncodedWithXMLCoder">YES</bool> - <reference ref="117630796"/> - <reference ref="246635843"/> - <reference ref="660549409"/> - </object> - <reference key="parent" ref="398561686"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">61</int> - <reference key="object" ref="117630796"/> - <reference key="parent" ref="767450548"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">62</int> - <reference key="object" ref="344412831"/> - <reference key="parent" ref="1035953805"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">63</int> - <reference key="object" ref="448429887"/> - <object class="NSMutableArray" key="children"> - <bool key="EncodedWithXMLCoder">YES</bool> - <reference ref="383305928"/> - </object> - <reference key="parent" ref="1035953805"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">64</int> - <reference key="object" ref="383305928"/> - <object class="NSMutableArray" key="children"> - <bool key="EncodedWithXMLCoder">YES</bool> - <reference ref="688272012"/> - <reference ref="830865062"/> - <reference ref="712404949"/> - </object> - <reference key="parent" ref="448429887"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">65</int> - <reference key="object" ref="688272012"/> - <reference key="parent" ref="383305928"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">66</int> - <reference key="object" ref="275495410"/> - <object class="NSMutableArray" key="children"> - <bool key="EncodedWithXMLCoder">YES</bool> - <reference ref="1054137046"/> - </object> - <reference key="parent" ref="1035953805"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">67</int> - <reference key="object" ref="1054137046"/> - <object class="NSMutableArray" key="children"> - <bool key="EncodedWithXMLCoder">YES</bool> - </object> - <reference key="parent" ref="275495410"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">69</int> - <reference key="object" ref="966232471"/> - <reference key="parent" ref="1035953805"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">70</int> - <reference key="object" ref="236901479"/> - <reference key="parent" ref="1035953805"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">82</int> - <reference key="object" ref="246635843"/> - <reference key="parent" ref="767450548"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">83</int> - <reference key="object" ref="660549409"/> - <reference key="parent" ref="767450548"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">87</int> - <reference key="object" ref="830865062"/> - <reference key="parent" ref="383305928"/> - </object> - <object class="IBObjectRecord"> - <int key="objectID">88</int> - <reference key="object" ref="712404949"/> - <reference key="parent" ref="383305928"/> - </object> - <object class="IBObjectRecord"> <int key="objectID">96</int> <reference key="object" ref="805002579"/> <reference key="parent" ref="558188039"/> @@ -1583,11 +1048,6 @@ <reference key="parent" ref="835640952"/> </object> <object class="IBObjectRecord"> - <int key="objectID">127</int> - <reference key="object" ref="633871226"/> - <reference key="parent" ref="1035953805"/> - </object> - <object class="IBObjectRecord"> <int key="objectID">129</int> <reference key="object" ref="306298564"/> <reference key="parent" ref="558188039"/> @@ -1655,7 +1115,6 @@ <string>12.CustomClassName</string> <string>12.IBPluginDependency</string> <string>122.IBPluginDependency</string> - <string>127.IBPluginDependency</string> <string>129.IBPluginDependency</string> <string>13.CustomClassName</string> <string>13.IBPluginDependency</string> @@ -1692,47 +1151,17 @@ <string>39.IBPluginDependency</string> <string>4.CustomClassName</string> <string>4.IBPluginDependency</string> - <string>42.IBEditorWindowLastContentRect</string> - <string>42.IBPluginDependency</string> - <string>43.IBPluginDependency</string> - <string>44.IBPluginDependency</string> - <string>45.IBPluginDependency</string> <string>48.IBEditorWindowLastContentRect</string> <string>48.IBPluginDependency</string> <string>49.IBPluginDependency</string> <string>5.IBPluginDependency</string> <string>50.IBPluginDependency</string> <string>51.IBPluginDependency</string> - <string>52.IBPluginDependency</string> - <string>53.IBPluginDependency</string> - <string>54.IBPluginDependency</string> - <string>55.IBPluginDependency</string> - <string>56.IBPluginDependency</string> - <string>57.IBPluginDependency</string> - <string>58.IBPluginDependency</string> - <string>59.IBPluginDependency</string> - <string>60.IBEditorWindowLastContentRect</string> - <string>60.IBPluginDependency</string> - <string>61.IBPluginDependency</string> - <string>62.IBPluginDependency</string> - <string>63.IBPluginDependency</string> - <string>64.IBEditorWindowLastContentRect</string> - <string>64.IBPluginDependency</string> - <string>65.IBPluginDependency</string> - <string>66.IBPluginDependency</string> - <string>67.IBEditorWindowLastContentRect</string> - <string>67.IBPluginDependency</string> - <string>69.IBPluginDependency</string> <string>7.CustomClassName</string> <string>7.IBAttributePlaceholdersKey</string> <string>7.IBPluginDependency</string> - <string>70.IBPluginDependency</string> <string>8.IBAttributePlaceholdersKey</string> <string>8.IBPluginDependency</string> - <string>82.IBPluginDependency</string> - <string>83.IBPluginDependency</string> - <string>87.IBPluginDependency</string> - <string>88.IBPluginDependency</string> <string>9.CustomClassName</string> <string>9.IBPluginDependency</string> <string>96.IBPluginDependency</string> @@ -1759,7 +1188,6 @@ <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>AutocompleteTextFieldCell</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> @@ -1831,37 +1259,12 @@ <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>AutocompleteTextField</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{444, 446}, {235, 293}}</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>{{48, 162}, {335, 333}}</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> - <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{404, 503}, {202, 63}}</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>{{1211, 422}, {201, 63}}</string> - <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{404, 540}, {64, 6}}</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> @@ -1872,7 +1275,6 @@ </object> </object> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <object class="NSMutableDictionary"> <string key="NS.key.0">ToolTip</string> <object class="IBToolTipAttribute" key="NS.object.0"> @@ -1882,10 +1284,6 @@ </object> </object> <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>ToolbarButtonCell</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> @@ -1941,11 +1339,13 @@ <bool key="EncodedWithXMLCoder">YES</bool> <string>closeTabMenuItem_</string> <string>closeWindowMenuItem_</string> + <string>helpMenu_</string> </object> <object class="NSMutableArray" key="dict.values"> <bool key="EncodedWithXMLCoder">YES</bool> <string>NSMenuItem</string> <string>NSMenuItem</string> + <string>NSMenu</string> </object> </object> <object class="IBClassDescriptionSource" key="sourceIdentifier"> diff --git a/chrome/browser/cocoa/menu_controller.h b/chrome/browser/cocoa/menu_controller.h new file mode 100644 index 0000000..d0a085f --- /dev/null +++ b/chrome/browser/cocoa/menu_controller.h @@ -0,0 +1,49 @@ +// Copyright (c) 2009 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_MENU_CONTROLLER_H_ +#define CHROME_BROWSER_COCOA_MENU_CONTROLLER_H_ + +#import <Cocoa/Cocoa.h> + +#include "base/scoped_nsobject.h" +#include "base/scoped_ptr.h" + +namespace menus { +class MenuModel; +} + +// A controller for the cross-platform menu model. The menu that's created +// has the tag and represented object set for each menu item. The object is a +// NSValue holding a pointer to the model for that level of the menu (to +// allow for hierarchical menus). The tag is the index into that model for +// that particular item. It is important that the model outlives this object +// as it only maintains weak references. +// TODO(pinkerton): Handle changes to the model. SimpleMenuModel doesn't yet +// notify when changes are made. +@interface MenuController : NSObject { + @private + scoped_nsobject<NSMenu> menu_; + BOOL useWithPopUpButtonCell_; // If YES, 0th item is blank +} + +// 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 +// slightly different form (0th item is empty). Note this attribute of the menu +// cannot be changed after it has been created. +- (id)initWithModel:(menus::MenuModel*)model + useWithPopUpButtonCell:(BOOL)useWithCell; + +// Access to the constructed menu. +- (NSMenu*)menu; + +@end + +// Exposed only for unit testing, do not call directly. +@interface MenuController(PrivateExposedForTesting) +- (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item; +@end + +#endif // CHROME_BROWSER_COCOA_MENU_CONTROLLER_H_ diff --git a/chrome/browser/cocoa/menu_controller.mm b/chrome/browser/cocoa/menu_controller.mm new file mode 100644 index 0000000..b63b663 --- /dev/null +++ b/chrome/browser/cocoa/menu_controller.mm @@ -0,0 +1,145 @@ +// Copyright (c) 2009 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/menu_controller.h" + +#include "app/l10n_util_mac.h" +#include "app/menus/simple_menu_model.h" +#include "base/logging.h" +#include "base/sys_string_conversions.h" + +@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 + +- (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]; + } + } + return self; +} + +// Creates a NSMenu from the given model. If the model has submenus, this can +// be invoked recursively. +- (NSMenu*)menuFromModel:(menus::MenuModel*)model { + NSMenu* menu = [[[NSMenu alloc] initWithTitle:@""] autorelease]; + + // The indices may not always start at zero (the windows system menu is one + // example where this is used) so just make sure we can handle it. + // SimpleMenuModel currently always starts at 0. + int firstItemIndex = model->GetFirstItemIndex(menu); + DCHECK(firstItemIndex == 0); + const int count = model->GetItemCount(); + for (int index = firstItemIndex; index < firstItemIndex + count; index++) { + int modelIndex = index - firstItemIndex; + if (model->GetTypeAt(modelIndex) == menus::MenuModel::TYPE_SEPARATOR) { + [self addSeparatorToMenu:menu atIndex:index]; + } else { + [self addItemToMenu:menu atIndex:index fromModel:model + modelIndex:modelIndex]; + } + } + + return menu; +} + +// Adds a separator item at the given index. As the separator doesn't need +// anything from the model, this method doesn't need the model index as the +// other method below does. +- (void)addSeparatorToMenu:(NSMenu*)menu + atIndex:(int)index { + NSMenuItem* separator = [NSMenuItem separatorItem]; + [menu insertItem:separator atIndex:index]; +} + +// 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 + fromModel:(menus::MenuModel*)model + modelIndex:(int)modelIndex { + NSString* label = + l10n_util::FixUpWindowsStyleLabel(model->GetLabelAt(modelIndex)); + scoped_nsobject<NSMenuItem> item( + [[NSMenuItem alloc] initWithTitle:label + action:@selector(itemSelected:) + keyEquivalent:@""]); + menus::MenuModel::ItemType type = model->GetTypeAt(modelIndex); + if (type == menus::MenuModel::TYPE_SUBMENU) { + // Recursively build a submenu from the sub-model at this index. + [item setTarget:nil]; + [item setAction:nil]; + menus::MenuModel* submenuModel = model->GetSubmenuModelAt(modelIndex); + NSMenu* submenu = + [self menuFromModel:(menus::SimpleMenuModel*)submenuModel]; + [item setSubmenu:submenu]; + } else { + // The MenuModel works on indexes so we can't just set the command id as the + // tag like we do in other menus. Also set the represented object to be + // the model so hierarchical menus check the correct index in the correct + // model. + [item setTag:modelIndex]; + [item setTarget:self]; + NSValue* modelObject = [NSValue valueWithPointer:model]; + [item setRepresentedObject:modelObject]; // Retains |modelObject|. + } + [menu insertItem:item atIndex:index]; +} + +// Called before the menu is to be displayed to update the state (enabled, +// radio, etc) of each item in the menu. +- (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { + SEL action = [item action]; + if (action != @selector(itemSelected:)) + return NO; + + NSInteger modelIndex = [item tag]; + menus::MenuModel* model = + static_cast<menus::MenuModel*>( + [[(id)item representedObject] pointerValue]); + DCHECK(model); + if (model) { + BOOL checked = model->IsItemCheckedAt(modelIndex); + DCHECK([(id)item isKindOfClass:[NSMenuItem class]]); + [(id)item setState:(checked ? NSOnState : NSOffState)]; + return model->IsEnabledAt(modelIndex); + } + return NO; +} + +// Called when the user chooses a particular menu item. |sender| is the menu +// item chosen. +- (void)itemSelected:(id)sender { + NSInteger modelIndex = [sender tag]; + menus::MenuModel* model = + static_cast<menus::MenuModel*>( + [[sender representedObject] pointerValue]); + DCHECK(model); + if (model); + model->ActivatedAt(modelIndex); +} + +- (NSMenu*)menu { + return menu_.get(); +} + +@end diff --git a/chrome/browser/cocoa/menu_controller_unittest.mm b/chrome/browser/cocoa/menu_controller_unittest.mm new file mode 100644 index 0000000..50bbf93 --- /dev/null +++ b/chrome/browser/cocoa/menu_controller_unittest.mm @@ -0,0 +1,177 @@ +// Copyright (c) 2009 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 <Cocoa/Cocoa.h> + +#include "app/menus/simple_menu_model.h" +#include "base/sys_string_conversions.h" +#include "base/utf_string_conversions.h" +#include "chrome/browser/cocoa/cocoa_test_helper.h" +#include "chrome/browser/cocoa/menu_controller.h" +#include "grit/generated_resources.h" + +class MenuControllerTest : public CocoaTest { +}; + +// A menu delegate that counts the number of times certain things are called +// to make sure things are hooked up properly. +class Delegate : public menus::SimpleMenuModel::Delegate { + public: + Delegate() : execute_count_(0), enable_count_(0) { } + + virtual bool IsCommandIdChecked(int command_id) const { return false; } + virtual bool IsCommandIdEnabled(int command_id) const { + ++enable_count_; + return true; + } + virtual bool GetAcceleratorForCommandId( + int command_id, + menus::Accelerator* accelerator) { return false; } + virtual void ExecuteCommand(int command_id) { ++execute_count_; } + + int execute_count_; + mutable int enable_count_; +}; + +TEST_F(MenuControllerTest, EmptyMenu) { + Delegate delegate; + menus::SimpleMenuModel model(&delegate); + scoped_nsobject<MenuController> menu( + [[MenuController alloc] initWithModel:&model useWithPopUpButtonCell:NO]); + EXPECT_EQ([[menu menu] numberOfItems], 0); +} + +TEST_F(MenuControllerTest, BasicCreation) { + Delegate delegate; + menus::SimpleMenuModel model(&delegate); + model.AddItem(1, WideToUTF16(L"one")); + model.AddItem(2, WideToUTF16(L"two")); + model.AddItem(3, WideToUTF16(L"three")); + model.AddSeparator(); + model.AddItem(4, WideToUTF16(L"four")); + model.AddItem(5, WideToUTF16(L"five")); + + scoped_nsobject<MenuController> menu( + [[MenuController alloc] initWithModel:&model useWithPopUpButtonCell:NO]); + EXPECT_EQ([[menu menu] numberOfItems], 6); + + // Check the title, tag, and represented object are correct for a random + // element. + NSMenuItem* itemTwo = [[menu menu] itemAtIndex:2]; + NSString* title = [itemTwo title]; + EXPECT_EQ(WideToUTF16(L"three"), base::SysNSStringToUTF16(title)); + EXPECT_EQ([itemTwo tag], 2); + EXPECT_EQ([[itemTwo representedObject] pointerValue], &model); + + EXPECT_TRUE([[[menu menu] itemAtIndex:3] isSeparatorItem]); +} + +TEST_F(MenuControllerTest, Submenus) { + Delegate delegate; + menus::SimpleMenuModel model(&delegate); + model.AddItem(1, WideToUTF16(L"one")); + menus::SimpleMenuModel submodel(&delegate); + submodel.AddItem(2, WideToUTF16(L"sub-one")); + submodel.AddItem(3, WideToUTF16(L"sub-two")); + submodel.AddItem(4, WideToUTF16(L"sub-three")); + model.AddSubMenuWithStringId(IDS_ZOOM_MENU, &submodel); + model.AddItem(5, WideToUTF16(L"three")); + + scoped_nsobject<MenuController> menu( + [[MenuController alloc] initWithModel:&model useWithPopUpButtonCell:NO]); + EXPECT_EQ([[menu menu] numberOfItems], 3); + + // Inspect the submenu to ensure it has correct properties. + NSMenu* submenu = [[[menu menu] itemAtIndex:1] submenu]; + EXPECT_TRUE(submenu); + EXPECT_EQ([submenu numberOfItems], 3); + + // Inspect one of the items to make sure it has the correct model as its + // represented object and the proper tag. + NSMenuItem* submenuItem = [submenu itemAtIndex:1]; + NSString* title = [submenuItem title]; + EXPECT_EQ(WideToUTF16(L"sub-two"), base::SysNSStringToUTF16(title)); + EXPECT_EQ([submenuItem tag], 1); + EXPECT_EQ([[submenuItem representedObject] pointerValue], &submodel); + + // Make sure the item after the submenu is correct and its represented + // object is back to the top model. + NSMenuItem* item = [[menu menu] itemAtIndex:2]; + title = [item title]; + EXPECT_EQ(WideToUTF16(L"three"), base::SysNSStringToUTF16(title)); + EXPECT_EQ([item tag], 2); + EXPECT_EQ([[item representedObject] pointerValue], &model); +} + +TEST_F(MenuControllerTest, EmptySubmenu) { + Delegate delegate; + menus::SimpleMenuModel model(&delegate); + model.AddItem(1, WideToUTF16(L"one")); + menus::SimpleMenuModel submodel(&delegate); + model.AddSubMenuWithStringId(IDS_ZOOM_MENU, &submodel); + + scoped_nsobject<MenuController> menu( + [[MenuController alloc] initWithModel:&model useWithPopUpButtonCell:NO]); + EXPECT_EQ([[menu menu] numberOfItems], 2); +} + +TEST_F(MenuControllerTest, PopUpButton) { + Delegate delegate; + menus::SimpleMenuModel model(&delegate); + model.AddItem(1, WideToUTF16(L"one")); + model.AddItem(2, WideToUTF16(L"two")); + model.AddItem(3, WideToUTF16(L"three")); + + // Menu should have an extra item inserted at position 0 that has an empty + // title. + scoped_nsobject<MenuController> menu( + [[MenuController alloc] initWithModel:&model useWithPopUpButtonCell:YES]); + EXPECT_EQ([[menu menu] numberOfItems], 4); + EXPECT_EQ(base::SysNSStringToUTF16([[[menu menu] itemAtIndex:0] title]), + string16()); + + // Make sure the tags are still correct (the index no longer matches the tag). + NSMenuItem* itemTwo = [[menu menu] itemAtIndex:2]; + EXPECT_EQ([itemTwo tag], 1); +} + +TEST_F(MenuControllerTest, Execute) { + Delegate delegate; + menus::SimpleMenuModel model(&delegate); + model.AddItem(1, WideToUTF16(L"one")); + scoped_nsobject<MenuController> menu( + [[MenuController alloc] initWithModel:&model useWithPopUpButtonCell:NO]); + EXPECT_EQ([[menu menu] numberOfItems], 1); + + // Fake selecting the menu item, we expect the delegate to be told to execute + // a command. + NSMenuItem* item = [[menu menu] itemAtIndex:0]; + [[item target] performSelector:[item action] withObject:item]; + EXPECT_EQ(delegate.execute_count_, 1); +} + +void Validate(MenuController* controller, NSMenu* menu) { + for (int i = 0; i < [menu numberOfItems]; ++i) { + NSMenuItem* item = [menu itemAtIndex:i]; + [controller validateUserInterfaceItem:item]; + if ([item hasSubmenu]) + Validate(controller, [item submenu]); + } +} + +TEST_F(MenuControllerTest, Validate) { + Delegate delegate; + menus::SimpleMenuModel model(&delegate); + model.AddItem(1, WideToUTF16(L"one")); + model.AddItem(2, WideToUTF16(L"two")); + menus::SimpleMenuModel submodel(&delegate); + submodel.AddItem(2, WideToUTF16(L"sub-one")); + model.AddSubMenuWithStringId(IDS_ZOOM_MENU, &submodel); + + scoped_nsobject<MenuController> menu( + [[MenuController alloc] initWithModel:&model useWithPopUpButtonCell:NO]); + EXPECT_EQ([[menu menu] numberOfItems], 3); + + Validate(menu.get(), [menu menu]); +} diff --git a/chrome/browser/cocoa/toolbar_controller.h b/chrome/browser/cocoa/toolbar_controller.h index 3801667..dfbe5bf 100644 --- a/chrome/browser/cocoa/toolbar_controller.h +++ b/chrome/browser/cocoa/toolbar_controller.h @@ -25,7 +25,10 @@ class CommandUpdater; class LocationBar; class LocationBarViewMac; @class MenuButton; +@class MenuController; +class PageMenuModel; namespace ToolbarControllerInternal { +class MenuDelegate; class PrefObserverBridge; } class Profile; @@ -52,6 +55,13 @@ class ToolbarModel; scoped_nsobject<BackForwardMenuController> forwardMenuController_; scoped_nsobject<BrowserActionsController> browserActionsController_; + // Lazily-instantiated model, controller, and delegate for the menu on the + // page button. If it's visible, these will be non-null, but they are not + // reaped when the button is hidden once it is initially shown. + scoped_ptr<PageMenuModel> pageMenuModel_; + scoped_nsobject<MenuController> pageMenuController_; + scoped_ptr<ToolbarControllerInternal::MenuDelegate> pageMenuDelegate_; + // Used for monitoring the optional toolbar button prefs. scoped_ptr<ToolbarControllerInternal::PrefObserverBridge> prefObserver_; // Used to position the omnibox bubble. @@ -86,7 +96,6 @@ class ToolbarModel; IBOutlet MenuButton* pageButton_; IBOutlet MenuButton* wrenchButton_; IBOutlet AutocompleteTextField* locationBar_; - IBOutlet NSMenu* encodingMenu_; IBOutlet NSView* browserActionContainerView_; } diff --git a/chrome/browser/cocoa/toolbar_controller.mm b/chrome/browser/cocoa/toolbar_controller.mm index 3b89ddc..8a13f25 100644 --- a/chrome/browser/cocoa/toolbar_controller.mm +++ b/chrome/browser/cocoa/toolbar_controller.mm @@ -11,6 +11,7 @@ #include "base/gfx/rect.h" #include "chrome/app/chrome_dll_resource.h" #include "chrome/browser/autocomplete/autocomplete_edit_view.h" +#include "chrome/browser/browser.h" #include "chrome/browser/bubble_positioner.h" #import "chrome/browser/cocoa/autocomplete_text_field.h" #import "chrome/browser/cocoa/autocomplete_text_field_editor.h" @@ -21,7 +22,9 @@ #import "chrome/browser/cocoa/gradient_button_cell.h" #import "chrome/browser/cocoa/location_bar_view_mac.h" #import "chrome/browser/cocoa/menu_button.h" +#import "chrome/browser/cocoa/menu_controller.h" #import "chrome/browser/cocoa/toolbar_view.h" +#include "chrome/browser/page_menu_model.h" #include "chrome/browser/profile.h" #include "chrome/browser/search_engines/template_url_model.h" #include "chrome/browser/toolbar_model.h" @@ -81,11 +84,40 @@ class BubblePositionerMac : public BubblePositioner { namespace ToolbarControllerInternal { +// A C++ delegate that handles enabling/disabling menu items and handling when +// a menu command is chosen. +class MenuDelegate : public menus::SimpleMenuModel::Delegate { + public: + explicit MenuDelegate(Browser* browser) + : browser_(browser) { } + + // Overridden from menus::SimpleMenuModel::Delegate + virtual bool IsCommandIdChecked(int command_id) const { + if (command_id == IDC_SHOW_BOOKMARK_BAR) { + return browser_->profile()->GetPrefs()->GetBoolean( + prefs::kShowBookmarkBar); + } + return false; + } + virtual bool IsCommandIdEnabled(int command_id) const { + return browser_->command_updater()->IsCommandEnabled(command_id); + } + virtual bool GetAcceleratorForCommandId( + int command_id, + menus::Accelerator* accelerator) { return false; } + virtual void ExecuteCommand(int command_id) { + browser_->ExecuteCommand(command_id); + } + + private: + Browser* browser_; +}; + // A C++ class registered for changes in preferences. Bridges the // notification back to the ToolbarController. class PrefObserverBridge : public NotificationObserver { public: - PrefObserverBridge(ToolbarController* controller) + explicit PrefObserverBridge(ToolbarController* controller) : controller_(controller) { } // Overridden from NotificationObserver: virtual void Observe(NotificationType type, @@ -221,8 +253,6 @@ class PrefObserverBridge : public NotificationObserver { // We want a dynamic tooltip on the go button, so tell the go button to ask // use for the tooltip [goButton_ addToolTipRect:[goButton_ bounds] owner:self userData:nil]; - - EncodingMenuControllerDelegate::BuildEncodingMenu(profile_, encodingMenu_); } - (void)mouseExited:(NSEvent*)theEvent { @@ -389,7 +419,7 @@ class PrefObserverBridge : public NotificationObserver { - (NSArray*)toolbarViews { return [NSArray arrayWithObjects:backButton_, forwardButton_, reloadButton_, homeButton_, starButton_, goButton_, pageButton_, wrenchButton_, - locationBar_, encodingMenu_, browserActionContainerView_, nil]; + locationBar_, browserActionContainerView_, nil]; } // Moves |rect| to the right by |delta|, keeping the right side fixed by @@ -433,6 +463,20 @@ class PrefObserverBridge : public NotificationObserver { [homeButton_ setHidden:hide]; } +// Lazily install the menus on the page and wrench buttons. Calling this +// repeatedly is inexpensive so it can be done every time the buttons are shown. +- (void)installPageWrenchMenus { + if (pageMenuModel_.get()) + return; + pageMenuDelegate_.reset( + new ToolbarControllerInternal::MenuDelegate(browser_)); + pageMenuModel_.reset(new PageMenuModel(pageMenuDelegate_.get(), browser_)); + pageMenuController_.reset( + [[MenuController alloc] initWithModel:pageMenuModel_.get() + useWithPopUpButtonCell:YES]); + [pageButton_ setAttachedMenu:[pageMenuController_ menu]]; +} + // Show or hide the page and wrench buttons based on the pref. - (void)showOptionalPageWrenchButtons { // Ignore this message if only showing the URL bar. @@ -440,6 +484,8 @@ class PrefObserverBridge : public NotificationObserver { return; DCHECK([pageButton_ isHidden] == [wrenchButton_ isHidden]); BOOL hide = showPageOptionButtons_.GetValue() ? NO : YES; + if (!hide) + [self installPageWrenchMenus]; if (hide == [pageButton_ isHidden]) return; // Nothing to do, view state matches pref state. diff --git a/chrome/browser/cocoa/toolbar_controller_unittest.mm b/chrome/browser/cocoa/toolbar_controller_unittest.mm index a6869c3..f7a2310 100644 --- a/chrome/browser/cocoa/toolbar_controller_unittest.mm +++ b/chrome/browser/cocoa/toolbar_controller_unittest.mm @@ -44,7 +44,7 @@ class ToolbarControllerTest : public CocoaTest { // |-toolbarViews| method. enum { kBackIndex, kForwardIndex, kReloadIndex, kHomeIndex, kStarIndex, kGoIndex, - kPageIndex, kWrenchIndex, kLocationIndex, kEncodingMenuIndex, + kPageIndex, kWrenchIndex, kLocationIndex, kBrowserActionContainerViewIndex }; @@ -283,13 +283,4 @@ TEST_F(ToolbarControllerTest, HoverButtonForEvent) { EXPECT_TRUE([bar_ hoverButtonForEvent:nil]); } -TEST_F(ToolbarControllerTest, PopulateEncodingMenu) { - NSMenu* encodings = [[bar_ toolbarViews] objectAtIndex:kEncodingMenuIndex]; - - // Can't check item strings because of localization, but the nib has zero - // items so check that we at least populated the menu with something at - // startup. - EXPECT_NE(0, [encodings numberOfItems]); -} - } // namespace diff --git a/chrome/browser/page_menu_model.cc b/chrome/browser/page_menu_model.cc new file mode 100644 index 0000000..6c88d4f --- /dev/null +++ b/chrome/browser/page_menu_model.cc @@ -0,0 +1,138 @@ +// Copyright (c) 2009 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 "chrome/browser/page_menu_model.h" + +#include "app/l10n_util.h" +#include "base/compiler_specific.h" +#include "chrome/app/chrome_dll_resource.h" +#include "chrome/browser/browser.h" +#include "chrome/browser/browser_process.h" +#include "chrome/browser/encoding_menu_controller.h" +#include "chrome/browser/tab_contents/tab_contents.h" +#include "grit/generated_resources.h" + +PageMenuModel::PageMenuModel(menus::SimpleMenuModel::Delegate* delegate, + Browser* browser) + : menus::SimpleMenuModel(delegate), browser_(browser) { + Build(); +} + +void PageMenuModel::Build() { + AddItemWithStringId(IDC_CREATE_SHORTCUTS, IDS_CREATE_SHORTCUTS); + AddSeparator(); + AddItemWithStringId(IDC_CUT, IDS_CUT); + AddItemWithStringId(IDC_COPY, IDS_COPY); + AddItemWithStringId(IDC_PASTE, IDS_PASTE); + AddSeparator(); + AddItemWithStringId(IDC_FIND, IDS_FIND); + AddItemWithStringId(IDC_SAVE_PAGE, IDS_SAVE_PAGE); + AddItemWithStringId(IDC_PRINT, IDS_PRINT); + AddSeparator(); + + zoom_menu_model_.reset(new ZoomMenuModel(delegate())); + AddSubMenuWithStringId(IDS_ZOOM_MENU, zoom_menu_model_.get()); + + encoding_menu_model_.reset(new EncodingMenuModel(browser_)); + AddSubMenuWithStringId(IDS_ENCODING_MENU, encoding_menu_model_.get()); + +#if !defined(OS_CHROMEOS) + AddSeparator(); + devtools_menu_model_.reset(new DevToolsMenuModel(delegate())); + AddSubMenuWithStringId(IDS_DEVELOPER_MENU, devtools_menu_model_.get()); + + AddSeparator(); + AddItemWithStringId(IDC_REPORT_BUG, IDS_REPORT_BUG); +#else + NOTIMPLEMENTED(); +#endif +} + +//////////////////////////////////////////////////////////////////////////////// +// EncodingMenuModel + +EncodingMenuModel::EncodingMenuModel(Browser* browser) + : ALLOW_THIS_IN_INITIALIZER_LIST(menus::SimpleMenuModel(this)), + browser_(browser) { + Build(); +} + +void EncodingMenuModel::Build() { + EncodingMenuController::EncodingMenuItemList encoding_menu_items; + EncodingMenuController encoding_menu_controller; + encoding_menu_controller.GetEncodingMenuItems(browser_->profile(), + &encoding_menu_items); + + int group_id = 0; + EncodingMenuController::EncodingMenuItemList::iterator it = + encoding_menu_items.begin(); + for (; it != encoding_menu_items.end(); ++it) { + int id = it->first; + string16& label = it->second; + if (id == 0) { + AddSeparator(); + } else { + if (id == IDC_ENCODING_AUTO_DETECT) { + AddCheckItem(id, label); + } else { + // Use the id of the first radio command as the id of the group. + if (group_id <= 0) + group_id = id; + AddRadioItem(id, label, group_id); + } + } + } +} + +bool EncodingMenuModel::IsCommandIdChecked(int command_id) const { + TabContents* current_tab = browser_->GetSelectedTabContents(); + EncodingMenuController controller; + return controller.IsItemChecked(browser_->profile(), + current_tab->encoding(), command_id); +} + +bool EncodingMenuModel::IsCommandIdEnabled(int command_id) const { + return browser_->command_updater()->IsCommandEnabled(command_id); +} + +bool EncodingMenuModel::GetAcceleratorForCommandId( + int command_id, + menus::Accelerator* accelerator) { + return false; +} + +void EncodingMenuModel::ExecuteCommand(int command_id) { + browser_->ExecuteCommand(command_id); +} + +//////////////////////////////////////////////////////////////////////////////// +// ZoomMenuModel + +ZoomMenuModel::ZoomMenuModel(menus::SimpleMenuModel::Delegate* delegate) + : SimpleMenuModel(delegate) { + Build(); +} + +void ZoomMenuModel::Build() { + AddItemWithStringId(IDC_ZOOM_PLUS, IDS_ZOOM_PLUS); + AddItemWithStringId(IDC_ZOOM_NORMAL, IDS_ZOOM_NORMAL); + AddItemWithStringId(IDC_ZOOM_MINUS, IDS_ZOOM_MINUS); +} + +//////////////////////////////////////////////////////////////////////////////// +// DevToolsMenuModel + +DevToolsMenuModel::DevToolsMenuModel(menus::SimpleMenuModel::Delegate* delegate) + : SimpleMenuModel(delegate) { + Build(); +} + +void DevToolsMenuModel::Build() { + AddItemWithStringId(IDC_VIEW_SOURCE, IDS_VIEW_SOURCE); + if (g_browser_process->have_inspector_files()) { + AddItemWithStringId(IDC_DEV_TOOLS, IDS_DEV_TOOLS); + AddItemWithStringId(IDC_DEV_TOOLS_CONSOLE, IDS_DEV_TOOLS_CONSOLE); + } + AddItemWithStringId(IDC_TASK_MANAGER, IDS_TASK_MANAGER); +} diff --git a/chrome/browser/page_menu_model.h b/chrome/browser/page_menu_model.h new file mode 100644 index 0000000..b3fc8ed --- /dev/null +++ b/chrome/browser/page_menu_model.h @@ -0,0 +1,82 @@ +// Copyright (c) 2009 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_PAGE_MENU_MODEL_H_ +#define CHROME_BROWSER_PAGE_MENU_MODEL_H_ + +#include "app/menus/simple_menu_model.h" +#include "base/scoped_ptr.h" + +class Browser; + +// A menu model that builds the contents of an encoding menu. +class EncodingMenuModel : public menus::SimpleMenuModel, + public menus::SimpleMenuModel::Delegate { + public: + explicit EncodingMenuModel(Browser* browser); + virtual ~EncodingMenuModel() {} + + // Overridden from menus::SimpleMenuModel::Delegate: + virtual bool IsCommandIdChecked(int command_id) const; + virtual bool IsCommandIdEnabled(int command_id) const; + virtual bool GetAcceleratorForCommandId(int command_id, + menus::Accelerator* accelerator); + virtual void ExecuteCommand(int command_id); + + private: + void Build(); + + Browser* browser_; // weak + + DISALLOW_COPY_AND_ASSIGN(EncodingMenuModel); +}; + +// A menu model that builds the contents of the zoom menu. +class ZoomMenuModel : public menus::SimpleMenuModel { + public: + explicit ZoomMenuModel(menus::SimpleMenuModel::Delegate* delegate); + virtual ~ZoomMenuModel() {} + + private: + void Build(); + + DISALLOW_COPY_AND_ASSIGN(ZoomMenuModel); +}; + +// A menu model that builds the contents of the dev tools menu. +class DevToolsMenuModel : public menus::SimpleMenuModel { + public: + explicit DevToolsMenuModel(menus::SimpleMenuModel::Delegate* delegate); + virtual ~DevToolsMenuModel() {} + + private: + void Build(); + + DISALLOW_COPY_AND_ASSIGN(DevToolsMenuModel); +}; + +// A menu model that builds the contents of the page menu and all of its +// submenus. +class PageMenuModel : public menus::SimpleMenuModel { + public: + explicit PageMenuModel(menus::SimpleMenuModel::Delegate* delegate, + Browser* browser); + virtual ~PageMenuModel() { } + + private: + void Build(); + + // The top-level model. + scoped_ptr<menus::SimpleMenuModel> model_; + // Models for submenus referenced by model_. SimpleMenuModel only uses weak + // references so these must be kept for the lifetime of the top-level model. + scoped_ptr<ZoomMenuModel> zoom_menu_model_; + scoped_ptr<EncodingMenuModel> encoding_menu_model_; + scoped_ptr<DevToolsMenuModel> devtools_menu_model_; + Browser* browser_; // weak + + DISALLOW_COPY_AND_ASSIGN(PageMenuModel); +}; + +#endif // CHROME_BROWSER_PAGE_MENU_MODEL_H_ diff --git a/chrome/browser/page_menu_model_unittest.cc b/chrome/browser/page_menu_model_unittest.cc new file mode 100644 index 0000000..e4a08ee --- /dev/null +++ b/chrome/browser/page_menu_model_unittest.cc @@ -0,0 +1,63 @@ +// Copyright (c) 2009 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 "chrome/browser/page_menu_model.h" + +#include "base/logging.h" +#include "chrome/test/browser_with_test_window_test.h" +#include "testing/gtest/include/gtest/gtest.h" + +// A menu delegate that counts the number of times certain things are called +// to make sure things are hooked up properly. +class Delegate : public menus::SimpleMenuModel::Delegate { + public: + Delegate() : execute_count_(0), enable_count_(0) { } + + virtual bool IsCommandIdChecked(int command_id) const { return false; } + virtual bool IsCommandIdEnabled(int command_id) const { + ++enable_count_; + return true; + } + virtual bool GetAcceleratorForCommandId( + int command_id, + menus::Accelerator* accelerator) { return false; } + virtual void ExecuteCommand(int command_id) { ++execute_count_; } + + int execute_count_; + mutable int enable_count_; +}; + +class PageMenuModelTest : public BrowserWithTestWindowTest { + public: +}; + +TEST_F(PageMenuModelTest, Basics) { + Delegate delegate; + PageMenuModel model(&delegate, browser()); + + // Verify it has items. The number varies by platform, so we don't check + // the exact number. + EXPECT_GT(model.GetItemCount(), 10); + + // Execute a couple of the items and make sure it gets back to our delegate. + model.ActivatedAt(0); + EXPECT_TRUE(model.IsEnabledAt(0)); + model.ActivatedAt(3); + EXPECT_TRUE(model.IsEnabledAt(3)); + EXPECT_EQ(delegate.execute_count_, 2); + EXPECT_EQ(delegate.enable_count_, 2); + + delegate.execute_count_ = 0; + delegate.enable_count_ = 0; + + // Choose something from the zoom submenu and make sure it makes it back to + // the delegate as well. + menus::MenuModel* zoomModel = model.GetSubmenuModelAt(10); + EXPECT_TRUE(zoomModel); + EXPECT_GT(zoomModel->GetItemCount(), 1); + zoomModel->ActivatedAt(1); + EXPECT_TRUE(zoomModel->IsEnabledAt(1)); + EXPECT_EQ(delegate.execute_count_, 1); + EXPECT_EQ(delegate.enable_count_, 1); +} diff --git a/chrome/browser/views/toolbar_view.cc b/chrome/browser/views/toolbar_view.cc index 86576ea..8576656 100644 --- a/chrome/browser/views/toolbar_view.cc +++ b/chrome/browser/views/toolbar_view.cc @@ -77,77 +77,6 @@ static const int kPopupBottomSpacingGlass = 1; static SkBitmap* kPopupBackgroundEdge = NULL; //////////////////////////////////////////////////////////////////////////////// -// EncodingMenuModel - -EncodingMenuModel::EncodingMenuModel(Browser* browser) - : SimpleMenuModel(this), - browser_(browser) { - Build(); -} - -void EncodingMenuModel::Build() { - EncodingMenuController::EncodingMenuItemList encoding_menu_items; - EncodingMenuController encoding_menu_controller; - encoding_menu_controller.GetEncodingMenuItems(browser_->profile(), - &encoding_menu_items); - - int group_id = 0; - EncodingMenuController::EncodingMenuItemList::iterator it = - encoding_menu_items.begin(); - for (; it != encoding_menu_items.end(); ++it) { - int id = it->first; - string16& label = it->second; - if (id == 0) { - AddSeparator(); - } else { - if (id == IDC_ENCODING_AUTO_DETECT) { - AddCheckItem(id, label); - } else { - // Use the id of the first radio command as the id of the group. - if (group_id <= 0) - group_id = id; - AddRadioItem(id, label, group_id); - } - } - } -} - -bool EncodingMenuModel::IsCommandIdChecked(int command_id) const { - TabContents* current_tab = browser_->GetSelectedTabContents(); - EncodingMenuController controller; - return controller.IsItemChecked(browser_->profile(), - current_tab->encoding(), command_id); -} - -bool EncodingMenuModel::IsCommandIdEnabled(int command_id) const { - return browser_->command_updater()->IsCommandEnabled(command_id); -} - -bool EncodingMenuModel::GetAcceleratorForCommandId( - int command_id, - menus::Accelerator* accelerator) { - return false; -} - -void EncodingMenuModel::ExecuteCommand(int command_id) { - browser_->ExecuteCommand(command_id); -} - -//////////////////////////////////////////////////////////////////////////////// -// EncodingMenuModel - -ZoomMenuModel::ZoomMenuModel(menus::SimpleMenuModel::Delegate* delegate) - : SimpleMenuModel(delegate) { - Build(); -} - -void ZoomMenuModel::Build() { - AddItemWithStringId(IDC_ZOOM_PLUS, IDS_ZOOM_PLUS); - AddItemWithStringId(IDC_ZOOM_NORMAL, IDS_ZOOM_NORMAL); - AddItemWithStringId(IDC_ZOOM_MINUS, IDS_ZOOM_MINUS); -} - -//////////////////////////////////////////////////////////////////////////////// // ToolbarView, public: ToolbarView::ToolbarView(Browser* browser) @@ -835,7 +764,8 @@ void ToolbarView::LoadRightSideControlsImages() { } void ToolbarView::RunPageMenu(const gfx::Point& pt) { - CreatePageMenu(); + page_menu_model_.reset(new PageMenuModel(this, browser_)); + page_menu_menu_.reset(new views::Menu2(page_menu_model_.get())); page_menu_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); } @@ -844,63 +774,6 @@ void ToolbarView::RunAppMenu(const gfx::Point& pt) { app_menu_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); } -void ToolbarView::CreatePageMenu() { - if (page_menu_contents_.get()) - return; - - page_menu_contents_.reset(new menus::SimpleMenuModel(this)); - page_menu_contents_->AddItemWithStringId(IDC_CREATE_SHORTCUTS, - IDS_CREATE_SHORTCUTS); - page_menu_contents_->AddSeparator(); - page_menu_contents_->AddItemWithStringId(IDC_CUT, IDS_CUT); - page_menu_contents_->AddItemWithStringId(IDC_COPY, IDS_COPY); - page_menu_contents_->AddItemWithStringId(IDC_PASTE, IDS_PASTE); - page_menu_contents_->AddSeparator(); - page_menu_contents_->AddItemWithStringId(IDC_FIND, IDS_FIND); - page_menu_contents_->AddItemWithStringId(IDC_SAVE_PAGE, IDS_SAVE_PAGE); - page_menu_contents_->AddItemWithStringId(IDC_PRINT, IDS_PRINT); - page_menu_contents_->AddSeparator(); - - zoom_menu_contents_.reset(new ZoomMenuModel(this)); - page_menu_contents_->AddSubMenuWithStringId( - IDS_ZOOM_MENU, zoom_menu_contents_.get()); - - encoding_menu_contents_.reset(new EncodingMenuModel(browser_)); - page_menu_contents_->AddSubMenuWithStringId( - IDS_ENCODING_MENU, encoding_menu_contents_.get()); - -#if defined(OS_WIN) - CreateDevToolsMenuContents(); - page_menu_contents_->AddSeparator(); - page_menu_contents_->AddSubMenuWithStringId( - IDS_DEVELOPER_MENU, devtools_menu_contents_.get()); - - page_menu_contents_->AddSeparator(); - page_menu_contents_->AddItemWithStringId(IDC_REPORT_BUG, IDS_REPORT_BUG); -#else - NOTIMPLEMENTED(); -#endif - - page_menu_menu_.reset(new views::Menu2(page_menu_contents_.get())); -} - -#if defined(OS_WIN) -void ToolbarView::CreateDevToolsMenuContents() { - devtools_menu_contents_.reset(new menus::SimpleMenuModel(this)); - devtools_menu_contents_->AddItem(IDC_VIEW_SOURCE, - l10n_util::GetString(IDS_VIEW_SOURCE)); - if (g_browser_process->have_inspector_files()) { - devtools_menu_contents_->AddItem(IDC_DEV_TOOLS, - l10n_util::GetString(IDS_DEV_TOOLS)); - devtools_menu_contents_->AddItem( - IDC_DEV_TOOLS_CONSOLE, - l10n_util::GetString(IDS_DEV_TOOLS_CONSOLE)); - } - devtools_menu_contents_->AddItem(IDC_TASK_MANAGER, - l10n_util::GetString(IDS_TASK_MANAGER)); -} -#endif - void ToolbarView::CreateAppMenu() { // We always rebuild the app menu so that we can get the current state of // the sync system. diff --git a/chrome/browser/views/toolbar_view.h b/chrome/browser/views/toolbar_view.h index 6d1f1d0..5048fb1 100644 --- a/chrome/browser/views/toolbar_view.h +++ b/chrome/browser/views/toolbar_view.h @@ -12,6 +12,7 @@ #include "base/scoped_ptr.h" #include "chrome/browser/bubble_positioner.h" #include "chrome/browser/command_updater.h" +#include "chrome/browser/page_menu_model.h" #include "chrome/browser/user_data_manager.h" #include "chrome/browser/views/accessible_toolbar_view.h" #include "chrome/browser/views/go_button.h" @@ -32,39 +33,6 @@ namespace views { class Menu2; } -// A menu model that builds the contents of an encoding menu. -class EncodingMenuModel : public menus::SimpleMenuModel, - public menus::SimpleMenuModel::Delegate { - public: - explicit EncodingMenuModel(Browser* browser); - virtual ~EncodingMenuModel() {} - - // Overridden from menus::SimpleMenuModel::Delegate: - virtual bool IsCommandIdChecked(int command_id) const; - virtual bool IsCommandIdEnabled(int command_id) const; - virtual bool GetAcceleratorForCommandId(int command_id, - menus::Accelerator* accelerator); - virtual void ExecuteCommand(int command_id); - - private: - void Build(); - - Browser* browser_; - - DISALLOW_COPY_AND_ASSIGN(EncodingMenuModel); -}; - -class ZoomMenuModel : public menus::SimpleMenuModel { - public: - explicit ZoomMenuModel(menus::SimpleMenuModel::Delegate* delegate); - virtual ~ZoomMenuModel() {} - - private: - void Build(); - - DISALLOW_COPY_AND_ASSIGN(ZoomMenuModel); -}; - // The Browser Window's toolbar. class ToolbarView : public AccessibleToolbarView, public views::ViewMenuDelegate, @@ -175,12 +143,6 @@ class ToolbarView : public AccessibleToolbarView, void RunPageMenu(const gfx::Point& pt); void RunAppMenu(const gfx::Point& pt); - void CreatePageMenu(); - void CreateZoomMenuContents(); - void CreateEncodingMenuContents(); -#if defined(OS_WIN) - void CreateDevToolsMenuContents(); -#endif void CreateAppMenu(); // Types of display mode this toolbar can have. @@ -228,10 +190,7 @@ class ToolbarView : public AccessibleToolbarView, DisplayMode display_mode_; // The contents of the various menus. - scoped_ptr<menus::SimpleMenuModel> page_menu_contents_; - scoped_ptr<ZoomMenuModel> zoom_menu_contents_; - scoped_ptr<EncodingMenuModel> encoding_menu_contents_; - scoped_ptr<menus::SimpleMenuModel> devtools_menu_contents_; + scoped_ptr<PageMenuModel> page_menu_model_; scoped_ptr<menus::SimpleMenuModel> app_menu_contents_; // TODO(beng): build these into MenuButton. diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index ca3be53..805bbfe 100755 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -460,6 +460,8 @@ 'browser/cocoa/location_bar_view_mac.mm', 'browser/cocoa/menu_button.h', 'browser/cocoa/menu_button.mm', + 'browser/cocoa/menu_controller.h', + 'browser/cocoa/menu_controller.mm', 'browser/cocoa/multi_key_equivalent_button.h', 'browser/cocoa/multi_key_equivalent_button.mm', 'browser/cocoa/nsmenuitem_additions.h', @@ -1162,6 +1164,8 @@ 'browser/options_window.h', 'browser/page_info_model.cc', 'browser/page_info_model.h', + 'browser/page_menu_model.cc', + 'browser/page_menu_model.h', 'browser/page_state.cc', 'browser/page_state.h', 'browser/parsers/metadata_parser.h', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 660a2be..0c2e9e3 100755 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -612,6 +612,7 @@ 'browser/cocoa/history_menu_cocoa_controller_unittest.mm', 'browser/cocoa/hyperlink_button_cell_unittest.mm', 'browser/cocoa/menu_button_unittest.mm', + 'browser/cocoa/menu_controller_unittest.mm', 'browser/cocoa/nsimage_cache_unittest.mm', 'browser/cocoa/nsmenuitem_additions_unittest.mm', 'browser/cocoa/nswindow_local_state_unittest.mm', @@ -720,6 +721,7 @@ 'browser/net/url_fixer_upper_unittest.cc', 'browser/notifications/desktop_notifications_unittest.cc', 'browser/notifications/desktop_notifications_unittest.h', + 'browser/page_menu_model_unittest.cc', 'browser/password_manager/encryptor_unittest.cc', 'browser/password_manager/login_database_unittest.cc', 'browser/password_manager/password_form_manager_unittest.cc', |