diff options
author | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-06 22:01:09 +0000 |
---|---|---|
committer | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-06 22:01:09 +0000 |
commit | 49f95e9eccbb3d1c9ce7b6a46adff337ef831fe2 (patch) | |
tree | 69883d8bb25c97a9a1f8f0598322a3e947d4a5cf /chrome | |
parent | c0d43029bbd23a2648589896ec1257f6a7c32b62 (diff) | |
download | chromium_src-49f95e9eccbb3d1c9ce7b6a46adff337ef831fe2.zip chromium_src-49f95e9eccbb3d1c9ce7b6a46adff337ef831fe2.tar.gz chromium_src-49f95e9eccbb3d1c9ce7b6a46adff337ef831fe2.tar.bz2 |
Added menu item for sync to wrench menu.
Wrench menu item is right above "Preferences...". Chrome menu item will be added in a future CL right above "Clear Browsing Data...". Sync menu items are hidden if bookmark sync is disabled (the current default for OS X). UI decisions were made after consulting with Cole.
Added code in browser_window_controller.mm to update sync menu item dynamically.
Added unit tests.
BUG=23073
TEST=manual testing, trybots, unittests
Review URL: http://codereview.chromium.org/363017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31309 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/app/nibs/Toolbar.xib | 57 | ||||
-rw-r--r-- | chrome/browser/cocoa/browser_window_controller.h | 7 | ||||
-rw-r--r-- | chrome/browser/cocoa/browser_window_controller.mm | 69 | ||||
-rw-r--r-- | chrome/browser/cocoa/browser_window_controller_unittest.mm | 75 |
4 files changed, 204 insertions, 4 deletions
diff --git a/chrome/app/nibs/Toolbar.xib b/chrome/app/nibs/Toolbar.xib index 92ba964..06b94b1 100644 --- a/chrome/app/nibs/Toolbar.xib +++ b/chrome/app/nibs/Toolbar.xib @@ -2,12 +2,13 @@ <archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.03"> <data> <int key="IBDocument.SystemTarget">1050</int> - <string key="IBDocument.SystemVersion">9L30</string> + <string key="IBDocument.SystemVersion">9L31a</string> <string key="IBDocument.InterfaceBuilderVersion">677</string> <string key="IBDocument.AppKitVersion">949.54</string> <string key="IBDocument.HIToolboxVersion">353.00</string> <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> <bool key="EncodedWithXMLCoder">YES</bool> + <integer value="48"/> <integer value="42"/> </object> <object class="NSArray" key="IBDocument.PluginDependencies"> @@ -642,6 +643,28 @@ <reference key="NSOnImage" ref="610745052"/> <reference key="NSMixedImage" ref="1070349142"/> </object> + <object class="NSMenuItem" id="141550343"> + <reference key="NSMenu" ref="558188039"/> + <bool key="NSIsDisabled">YES</bool> + <bool key="NSIsHidden">YES</bool> + <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"/> + <int key="NSTag">41108</int> + </object> + <object class="NSMenuItem" id="892721848"> + <reference key="NSMenu" ref="558188039"/> + <bool key="NSIsDisabled">YES</bool> + <bool key="NSIsSeparator">YES</bool> + <bool key="NSIsHidden">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="510846575"> <reference key="NSMenu" ref="558188039"/> <string key="NSTitle">^IDS_PREFERENCES_MAC</string> @@ -1030,6 +1053,14 @@ </object> <int key="connectionID">139</int> </object> + <object class="IBConnectionRecord"> + <object class="IBActionConnection" key="connection"> + <string key="label">commandDispatch:</string> + <reference key="source" ref="1003"/> + <reference key="destination" ref="141550343"/> + </object> + <int key="connectionID">142</int> + </object> </object> <object class="IBMutableOrderedSet" key="objectRecords"> <object class="NSArray" key="orderedObjects"> @@ -1261,6 +1292,8 @@ <reference ref="922630377"/> <reference ref="510846575"/> <reference ref="306298564"/> + <reference ref="141550343"/> + <reference ref="892721848"/> </object> <reference key="parent" ref="465075988"/> </object> @@ -1481,6 +1514,16 @@ <reference key="object" ref="306232897"/> <reference key="parent" ref="465075988"/> </object> + <object class="IBObjectRecord"> + <int key="objectID">140</int> + <reference key="object" ref="141550343"/> + <reference key="parent" ref="558188039"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">141</int> + <reference key="object" ref="892721848"/> + <reference key="parent" ref="558188039"/> + </object> </object> </object> <object class="NSMutableDictionary" key="flattenedProperties"> @@ -1509,6 +1552,8 @@ <string>13.IBPluginDependency</string> <string>14.CustomClassName</string> <string>14.IBPluginDependency</string> + <string>140.IBPluginDependency</string> + <string>141.IBPluginDependency</string> <string>15.CustomClassName</string> <string>15.IBPluginDependency</string> <string>2.CustomClassName</string> @@ -1604,6 +1649,8 @@ <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>ToolbarButtonCell</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>ClickHoldButtonCell</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>DelayedMenuButton</string> @@ -1663,12 +1710,12 @@ <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>AutocompleteTextField</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{979, 432}, {235, 293}}</string> + <string>{{1454, 785}, {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>{{362, 523}, {306, 233}}</string> + <string>{{362, 493}, {335, 263}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> @@ -1746,7 +1793,7 @@ </object> </object> <nil key="sourceID"/> - <int key="maxID">139</int> + <int key="maxID">142</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> @@ -1982,6 +2029,7 @@ <string>customPagesArrayController_</string> <string>downloadLocationButton_</string> <string>downloadLocationControl_</string> + <string>enableLoggingCheckbox_</string> <string>personalStuffGroupAutofill_</string> <string>personalStuffGroupBrowserData_</string> <string>personalStuffGroupPasswords_</string> @@ -2003,6 +2051,7 @@ <string>NSArrayController</string> <string>NSButton</string> <string>NSPathControl</string> + <string>NSButton</string> <string>NSArray</string> <string>NSArray</string> <string>NSArray</string> diff --git a/chrome/browser/cocoa/browser_window_controller.h b/chrome/browser/cocoa/browser_window_controller.h index 49ebe34..de3451d 100644 --- a/chrome/browser/cocoa/browser_window_controller.h +++ b/chrome/browser/cocoa/browser_window_controller.h @@ -19,6 +19,7 @@ #import "chrome/browser/cocoa/bookmark_bubble_controller.h" #import "chrome/browser/cocoa/browser_command_executor.h" #import "chrome/browser/cocoa/view_resizer.h" +#include "chrome/browser/sync/sync_status_ui_helper.h" #import "third_party/GTM/AppKit/GTMTheme.h" class Browser; @@ -184,6 +185,12 @@ class TabStripModelObserverBridge; // Return a point suitable for the topLeft for a bookmark bubble. - (NSPoint)topLeftForBubble; +// Updates a bookmark sync UI item (expected to be a menu item). This is +// called every time the menu containing the sync UI item is displayed. +- (void)updateSyncItem:(id)syncItem + syncEnabled:(BOOL)syncEnabled + status:(SyncStatusUIHelper::MessageType)status; + @end // BrowserWindowController(TestingAPI) #endif // CHROME_BROWSER_COCOA_BROWSER_WINDOW_CONTROLLER_H_ diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm index f310c07..73781e4 100644 --- a/chrome/browser/cocoa/browser_window_controller.mm +++ b/chrome/browser/cocoa/browser_window_controller.mm @@ -4,6 +4,7 @@ #include <Carbon/Carbon.h> +#include "app/l10n_util_mac.h" #include "base/mac_util.h" #include "base/scoped_nsdisable_screen_updates.h" #import "base/scoped_nsobject.h" @@ -39,8 +40,10 @@ #import "chrome/browser/cocoa/tab_view.h" #import "chrome/browser/cocoa/toolbar_controller.h" #import "chrome/browser/browser_theme_provider.h" +#include "chrome/browser/sync/sync_status_ui_helper.h" #include "chrome/common/pref_service.h" #import "chrome/browser/cocoa/background_gradient_view.h" +#include "grit/generated_resources.h" #include "grit/theme_resources.h" #import "third_party/GTM/AppKit/GTMTheme.h" @@ -579,6 +582,19 @@ willPositionSheet:(NSWindow*)sheet case IDC_FULLSCREEN: enable &= [self supportsFullscreen]; break; + case IDC_SYNC_BOOKMARKS: + { + Profile* profile = browser_->profile()->GetOriginalProfile(); + ProfileSyncService* syncService = profile->GetProfileSyncService(); + // TODO(timsteele): Need a ui helper method to just get the type + // without needing labels. + string16 label, link; + SyncStatusUIHelper::MessageType status = + SyncStatusUIHelper::GetLabels(syncService, &label, &link); + enable &= (syncService != NULL); + [self updateSyncItem:item syncEnabled:enable status:status]; + } + break; default: // Special handling for the contents of the Text Encoding submenu. On // Mac OS, instead of enabling/disabling the top-level menu item, we @@ -599,6 +615,59 @@ willPositionSheet:(NSWindow*)sheet return enable; } +// TODO(akalin): We need to add a menu item to the main Chrome menu (near +// "Clear browsing data..."). However, this is tricky as no browsers may +// actually be open. Refactor the sync UI code so that it doesn't depend +// on a browser being present. + +- (void)updateSyncItem:(id)syncItem + syncEnabled:(BOOL)syncEnabled + status:(SyncStatusUIHelper::MessageType)status { + DCHECK([syncItem isKindOfClass:[NSMenuItem class]]); + NSMenuItem* syncMenuItem = (NSMenuItem*)syncItem; + // Look for a separator immediately after the menu item. + NSMenuItem* followingSeparator = nil; + NSMenu* menu = [syncItem menu]; + if (menu) { + NSInteger syncItemIndex = [menu indexOfItem:syncMenuItem]; + DCHECK_NE(syncItemIndex, -1); + if ((syncItemIndex + 1) < [menu numberOfItems]) { + NSMenuItem* menuItem = [menu itemAtIndex:(syncItemIndex + 1)]; + if ([menuItem isSeparatorItem]) { + followingSeparator = menuItem; + } + } + } + + // TODO(akalin): consolidate this code with the equivalent Windows code in + // chrome/browser/views/toolbar_view.cc. + int titleId; + switch (status) { + case SyncStatusUIHelper::SYNCED: + titleId = IDS_SYNC_MENU_BOOKMARKS_SYNCED_LABEL; + break; + case SyncStatusUIHelper::SYNC_ERROR: + titleId = IDS_SYNC_MENU_BOOKMARK_SYNC_ERROR_LABEL; + break; + case SyncStatusUIHelper::PRE_SYNCED: + titleId = IDS_SYNC_START_SYNC_BUTTON_LABEL; + break; + default: + NOTREACHED(); + // Needed to prevent release-mode warnings. + titleId = IDS_SYNC_START_SYNC_BUTTON_LABEL; + break; + } + NSString* title = l10n_util::GetNSStringWithFixup(titleId); + [syncMenuItem setTitle:title]; + + // If we don't have a sync service, hide any sync-related menu + // items. However, sync_menu_item is enabled/disabled outside of this + // function so we don't touch it here, and separators are always disabled. + [syncMenuItem setHidden:!syncEnabled]; + [followingSeparator setHidden:!syncEnabled]; +} + // Called when the user picks a menu or toolbar item when this window is key. // Calls through to the browser object to execute the command. This assumes that // the command is supported and doesn't check, otherwise it would have been diff --git a/chrome/browser/cocoa/browser_window_controller_unittest.mm b/chrome/browser/cocoa/browser_window_controller_unittest.mm index b5f504e..e2b7451 100644 --- a/chrome/browser/cocoa/browser_window_controller_unittest.mm +++ b/chrome/browser/cocoa/browser_window_controller_unittest.mm @@ -2,19 +2,23 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "app/l10n_util_mac.h" #include "base/scoped_nsobject.h" #include "base/scoped_nsautorelease_pool.h" #include "base/scoped_ptr.h" +#include "chrome/app/chrome_dll_resource.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/browser_window.h" #include "chrome/browser/cocoa/browser_test_helper.h" #include "chrome/browser/cocoa/browser_window_controller.h" #include "chrome/browser/cocoa/cocoa_test_helper.h" #include "chrome/browser/cocoa/find_bar_bridge.h" +#include "chrome/browser/sync/sync_status_ui_helper.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" #include "chrome/test/testing_browser_process.h" #include "chrome/test/testing_profile.h" +#include "grit/generated_resources.h" @interface BrowserWindowController (JustForTesting) // Already defined in BWC. @@ -429,6 +433,77 @@ TEST_F(BrowserWindowControllerTest, TestFindBarOnTop) { EXPECT_GT(findBar_index, bookmark_index); } +TEST_F(BrowserWindowControllerTest, TestSyncMenuItem) { + scoped_nsobject<NSMenuItem> syncMenuItem( + [[NSMenuItem alloc] initWithTitle:@"" + action:@selector(commandDispatch) + keyEquivalent:@""]); + [syncMenuItem setTag:IDC_SYNC_BOOKMARKS]; + + NSString* bookmarksSynced = + l10n_util::GetNSStringWithFixup(IDS_SYNC_MENU_BOOKMARKS_SYNCED_LABEL); + NSString* bookmarkSyncError = + l10n_util::GetNSStringWithFixup(IDS_SYNC_MENU_BOOKMARK_SYNC_ERROR_LABEL); + NSString* startSync = + l10n_util::GetNSStringWithFixup(IDS_SYNC_START_SYNC_BUTTON_LABEL); + + [syncMenuItem setTitle:@""]; + [syncMenuItem setHidden:NO]; + [controller_ updateSyncItem:syncMenuItem + syncEnabled:NO + status:SyncStatusUIHelper::PRE_SYNCED]; + EXPECT_TRUE([[syncMenuItem title] isEqualTo:startSync]); + EXPECT_TRUE([syncMenuItem isHidden]); + + [syncMenuItem setTitle:@""]; + [syncMenuItem setHidden:YES]; + [controller_ updateSyncItem:syncMenuItem + syncEnabled:YES + status:SyncStatusUIHelper::SYNC_ERROR]; + EXPECT_TRUE([[syncMenuItem title] isEqualTo:bookmarkSyncError]); + EXPECT_FALSE([syncMenuItem isHidden]); + + [syncMenuItem setTitle:@""]; + [syncMenuItem setHidden:NO]; + [controller_ updateSyncItem:syncMenuItem + syncEnabled:NO + status:SyncStatusUIHelper::SYNCED]; + EXPECT_TRUE([[syncMenuItem title] isEqualTo:bookmarksSynced]); + EXPECT_TRUE([syncMenuItem isHidden]); +} + +TEST_F(BrowserWindowControllerTest, TestSyncMenuItemWithSeparator) { + scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]); + NSMenuItem* syncMenuItem = + [menu addItemWithTitle:@"" + action:@selector(commandDispatch) + keyEquivalent:@""]; + [syncMenuItem setTag:IDC_SYNC_BOOKMARKS]; + NSMenuItem* following_separator = [NSMenuItem separatorItem]; + [menu addItem:following_separator]; + + const SyncStatusUIHelper::MessageType kStatus = + SyncStatusUIHelper::PRE_SYNCED; + + [syncMenuItem setHidden:NO]; + [following_separator setHidden:NO]; + [controller_ updateSyncItem:syncMenuItem + syncEnabled:NO + status:kStatus]; + EXPECT_FALSE([following_separator isEnabled]); + EXPECT_TRUE([syncMenuItem isHidden]); + EXPECT_TRUE([following_separator isHidden]); + + [syncMenuItem setHidden:YES]; + [following_separator setHidden:YES]; + [controller_ updateSyncItem:syncMenuItem + syncEnabled:YES + status:kStatus]; + EXPECT_FALSE([following_separator isEnabled]); + EXPECT_FALSE([syncMenuItem isHidden]); + EXPECT_FALSE([following_separator isHidden]); +} + @interface BrowserWindowControllerFakeFullscreen : BrowserWindowController { @private // We release the window ourselves, so we don't have to rely on the unittest |