diff options
author | jrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-02 00:12:26 +0000 |
---|---|---|
committer | jrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-02 00:12:26 +0000 |
commit | c5726b841ef81c0a6432cfd18381b82767cc15da (patch) | |
tree | 10f578b72f3368e7aa15742b84eb6627d1f0e829 | |
parent | 78263c1774421e5f451a549e754390cfbcc6b27e (diff) | |
download | chromium_src-c5726b841ef81c0a6432cfd18381b82767cc15da.zip chromium_src-c5726b841ef81c0a6432cfd18381b82767cc15da.tar.gz chromium_src-c5726b841ef81c0a6432cfd18381b82767cc15da.tar.bz2 |
Add the "Other bookmarks" button on the right of the bookmark bar.
Lots of fixes to deal better with the floating bar on the
NTP (e.g. chevron resize, chevron enabling only when there is
overflow, ...)
Move layoutSubviews logic from bookmark_bar_toolbar_view to
bookmark_bar_controller to better honor MVC.
BUG=http://crbug.com/24985, http://crbug.com/24827, http://crbug.com/22018
TEST=Lots of moves:
New browser with no bookmarks.
Go to New Tab Page. Show Bookmark Bar.
See "Other Bookmarks" button on right.
Do NOT see chevron.
Hover over and click on Other Bookmarks to be sure it doesn't draw out of bounds.
Disable bookmark bar (so it is now floating).
Repeat hover/click test.
Enable (so now attached).
Add bookmarks until chevron shows up.
Repeat hover/click test with chevron and Other Bookmarks.
Make browser wider and thinner; each time repeat hover/click test.
Detach bookmark bar (so floating on NTP).
Make browser wider and thinner; each time repeat hover/click test.
Carefully make browser wider/thinner so chevron appears/disappears.
Make sure chevron never overlaps a bookmark.
With chevron visible, quit & relaunch. Make sure chevron visible.
With chevron NOT visible, quit & relaunch. Make sure chevron not visible.
Review URL: http://codereview.chromium.org/348017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30684 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/nibs/BookmarkBar.xib | 585 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_constants.h | 3 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_controller.h | 8 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_controller.mm | 224 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_controller_unittest.mm | 58 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_toolbar_view.h | 9 | ||||
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_toolbar_view.mm | 18 |
7 files changed, 761 insertions, 144 deletions
diff --git a/chrome/app/nibs/BookmarkBar.xib b/chrome/app/nibs/BookmarkBar.xib index 52f4fa3..2cbbfa2 100644 --- a/chrome/app/nibs/BookmarkBar.xib +++ b/chrome/app/nibs/BookmarkBar.xib @@ -1,16 +1,20 @@ <?xml version="1.0" encoding="UTF-8"?> -<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.03"> +<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.10"> <data> <int key="IBDocument.SystemTarget">1050</int> - <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> + <string key="IBDocument.SystemVersion">10B504</string> + <string key="IBDocument.InterfaceBuilderVersion">732</string> + <string key="IBDocument.AppKitVersion">1038.2</string> + <string key="IBDocument.HIToolboxVersion">437.00</string> + <object class="NSMutableDictionary" key="IBDocument.PluginVersions"> + <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string> + <string key="NS.object.0">732</string> + </object> <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> <bool key="EncodedWithXMLCoder">YES</bool> + <integer value="4"/> <integer value="18"/> <integer value="1"/> - <integer value="4"/> </object> <object class="NSArray" key="IBDocument.PluginDependencies"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -18,7 +22,7 @@ </object> <object class="NSMutableDictionary" key="IBDocument.Metadata"> <bool key="EncodedWithXMLCoder">YES</bool> - <object class="NSArray" key="dict.sortedKeys"> + <object class="NSArray" key="dict.sortedKeys" id="0"> <bool key="EncodedWithXMLCoder">YES</bool> </object> <object class="NSMutableArray" key="dict.values"> @@ -51,6 +55,7 @@ <int key="NSvFlags">-2147483382</int> <string key="NSFrame">{{5, 123}, {579, 14}}</string> <reference key="NSSuperview" ref="610146462"/> + <int key="NSViewLayerContentsRedrawPolicy">2</int> <bool key="NSEnabled">YES</bool> <object class="NSTextFieldCell" key="NSCell" id="458754719"> <int key="NSCellFlags">68288064</int> @@ -58,7 +63,7 @@ <string key="NSContents">^IDS_BOOKMARKS_NO_ITEMS</string> <object class="NSFont" key="NSSupport"> <string key="NSName">LucidaGrande</string> - <double key="NSSize">1.100000e+01</double> + <double key="NSSize">11</double> <int key="NSfFlags">3100</int> </object> <reference key="NSControlView" ref="1013234954"/> @@ -68,7 +73,7 @@ <string key="NSColorName">controlColor</string> <object class="NSColor" key="NSColor"> <int key="NSColorSpace">3</int> - <bytes key="NSWhite">MC42NjY2NjY2OQA</bytes> + <bytes key="NSWhite">MC42NjY2NjY2NjY3AA</bytes> </object> </object> <object class="NSColor" key="NSTextColor"> @@ -83,15 +88,17 @@ </object> </object> </object> - <string key="NSFrameSize">{584, 144}</string> + <string key="NSFrame">{{0, -2}, {584, 144}}</string> <reference key="NSSuperview" ref="620641226"/> + <int key="NSViewLayerContentsRedrawPolicy">2</int> <string key="NSClassName">BookmarkBarView</string> </object> <object class="NSButton" id="1071220197"> <reference key="NSNextResponder" ref="620641226"/> - <int key="NSvFlags">305</int> + <int key="NSvFlags">277</int> <string key="NSFrame">{{586, 2}, {14, 28}}</string> <reference key="NSSuperview" ref="620641226"/> + <int key="NSViewLayerContentsRedrawPolicy">2</int> <bool key="NSEnabled">YES</bool> <object class="NSButtonCell" key="NSCell" id="1055451269"> <int key="NSCellFlags">67239424</int> @@ -111,8 +118,9 @@ </object> </object> </object> - <string key="NSFrameSize">{600, 144}</string> + <string key="NSFrameSize">{600, 142}</string> <reference key="NSSuperview"/> + <int key="NSViewLayerContentsRedrawPolicy">2</int> <string key="NSClassName">BookmarkBarToolbarView</string> </object> <object class="NSMenu" id="190917733"> @@ -628,14 +636,6 @@ </object> <object class="IBConnectionRecord"> <object class="IBOutletConnection" key="connection"> - <string key="label">buttonView_</string> - <reference key="source" ref="620641226"/> - <reference key="destination" ref="610146462"/> - </object> - <int key="connectionID">94</int> - </object> - <object class="IBConnectionRecord"> - <object class="IBOutletConnection" key="connection"> <string key="label">controller_</string> <reference key="source" ref="610146462"/> <reference key="destination" ref="1001"/> @@ -648,28 +648,26 @@ <bool key="EncodedWithXMLCoder">YES</bool> <object class="IBObjectRecord"> <int key="objectID">0</int> - <object class="NSArray" key="object" id="396810763"> - <bool key="EncodedWithXMLCoder">YES</bool> - </object> + <reference key="object" ref="0"/> <reference key="children" ref="1000"/> <nil key="parent"/> </object> <object class="IBObjectRecord"> <int key="objectID">-2</int> <reference key="object" ref="1001"/> - <reference key="parent" ref="396810763"/> - <string type="base64-UTF8" key="objectName">RmlsZSdzIE93bmVyA</string> + <reference key="parent" ref="0"/> + <string key="objectName">File's Owner</string> </object> <object class="IBObjectRecord"> <int key="objectID">-1</int> <reference key="object" ref="1003"/> - <reference key="parent" ref="396810763"/> + <reference key="parent" ref="0"/> <string key="objectName">First Responder</string> </object> <object class="IBObjectRecord"> <int key="objectID">-3</int> <reference key="object" ref="1004"/> - <reference key="parent" ref="396810763"/> + <reference key="parent" ref="0"/> <string key="objectName">Application</string> </object> <object class="IBObjectRecord"> @@ -680,7 +678,7 @@ <reference ref="610146462"/> <reference ref="1071220197"/> </object> - <reference key="parent" ref="396810763"/> + <reference key="parent" ref="0"/> </object> <object class="IBObjectRecord"> <int key="objectID">4</int> @@ -700,7 +698,7 @@ <reference ref="23014313"/> <reference ref="149427359"/> </object> - <reference key="parent" ref="396810763"/> + <reference key="parent" ref="0"/> <string key="objectName">Bar Menu</string> </object> <object class="IBObjectRecord"> @@ -782,7 +780,7 @@ <reference ref="1071747565"/> <reference ref="377013426"/> </object> - <reference key="parent" ref="396810763"/> + <reference key="parent" ref="0"/> <string key="objectName">Button Menu</string> </object> <object class="IBObjectRecord"> @@ -871,7 +869,7 @@ <object class="IBObjectRecord"> <int key="objectID">72</int> <reference key="object" ref="849863465"/> - <reference key="parent" ref="396810763"/> + <reference key="parent" ref="0"/> </object> <object class="IBObjectRecord"> <int key="objectID">75</int> @@ -880,7 +878,7 @@ <bool key="EncodedWithXMLCoder">YES</bool> <reference ref="582055256"/> </object> - <reference key="parent" ref="396810763"/> + <reference key="parent" ref="0"/> <string key="objectName">Off-the-side Menu</string> </object> <object class="IBObjectRecord"> @@ -911,7 +909,7 @@ </object> <object class="NSMutableDictionary" key="flattenedProperties"> <bool key="EncodedWithXMLCoder">YES</bool> - <object class="NSMutableArray" key="dict.sortedKeys"> + <object class="NSArray" key="dict.sortedKeys"> <bool key="EncodedWithXMLCoder">YES</bool> <string>-1.IBPluginDependency</string> <string>-2.IBPluginDependency</string> @@ -964,7 +962,7 @@ <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{191, 181}, {600, 144}}</string> + <string>{{199, 138}, {600, 142}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> @@ -973,7 +971,7 @@ <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{380, 426}, {365, 233}}</string> + <string>{{380, 426}, {362, 233}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> @@ -987,7 +985,7 @@ <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{268, 519}, {375, 213}}</string> + <string>{{268, 519}, {372, 213}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> @@ -1010,9 +1008,7 @@ </object> <object class="NSMutableDictionary" key="unlocalizedProperties"> <bool key="EncodedWithXMLCoder">YES</bool> - <object class="NSArray" key="dict.sortedKeys"> - <bool key="EncodedWithXMLCoder">YES</bool> - </object> + <reference key="dict.sortedKeys" ref="0"/> <object class="NSMutableArray" key="dict.values"> <bool key="EncodedWithXMLCoder">YES</bool> </object> @@ -1020,9 +1016,7 @@ <nil key="activeLocalization"/> <object class="NSMutableDictionary" key="localizations"> <bool key="EncodedWithXMLCoder">YES</bool> - <object class="NSArray" key="dict.sortedKeys"> - <bool key="EncodedWithXMLCoder">YES</bool> - </object> + <reference key="dict.sortedKeys" ref="0"/> <object class="NSMutableArray" key="dict.values"> <bool key="EncodedWithXMLCoder">YES</bool> </object> @@ -1046,7 +1040,7 @@ <string key="superclassName">NSViewController</string> <object class="NSMutableDictionary" key="actions"> <bool key="EncodedWithXMLCoder">YES</bool> - <object class="NSMutableArray" key="dict.sortedKeys"> + <object class="NSArray" key="dict.sortedKeys"> <bool key="EncodedWithXMLCoder">YES</bool> <string>addOrRenameFolder:</string> <string>addPage:</string> @@ -1077,7 +1071,7 @@ </object> <object class="NSMutableDictionary" key="outlets"> <bool key="EncodedWithXMLCoder">YES</bool> - <object class="NSMutableArray" key="dict.sortedKeys"> + <object class="NSArray" key="dict.sortedKeys"> <bool key="EncodedWithXMLCoder">YES</bool> <string>buttonContextMenu_</string> <string>buttonView_</string> @@ -1105,17 +1099,8 @@ <string key="className">BookmarkBarToolbarView</string> <string key="superclassName">BackgroundGradientView</string> <object class="NSMutableDictionary" key="outlets"> - <bool key="EncodedWithXMLCoder">YES</bool> - <object class="NSMutableArray" key="dict.sortedKeys"> - <bool key="EncodedWithXMLCoder">YES</bool> - <string>buttonView_</string> - <string>controller_</string> - </object> - <object class="NSMutableArray" key="dict.values"> - <bool key="EncodedWithXMLCoder">YES</bool> - <string>BookmarkBarView</string> - <string>id</string> - </object> + <string key="NS.key.0">controller_</string> + <string key="NS.object.0">id</string> </object> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBProjectSource</string> @@ -1127,7 +1112,7 @@ <string key="superclassName">NSView</string> <object class="NSMutableDictionary" key="outlets"> <bool key="EncodedWithXMLCoder">YES</bool> - <object class="NSMutableArray" key="dict.sortedKeys"> + <object class="NSArray" key="dict.sortedKeys"> <bool key="EncodedWithXMLCoder">YES</bool> <string>controller_</string> <string>noItemTextfield_</string> @@ -1176,7 +1161,7 @@ <string key="superclassName">NSObject</string> <object class="NSMutableDictionary" key="outlets"> <bool key="EncodedWithXMLCoder">YES</bool> - <object class="NSMutableArray" key="dict.sortedKeys"> + <object class="NSArray" key="dict.sortedKeys"> <bool key="EncodedWithXMLCoder">YES</bool> <string>otherObjectToLocalize_</string> <string>owner_</string> @@ -1215,6 +1200,13 @@ </object> </object> <object class="IBPartialClassDescription"> + <string key="className">NSMenuItem</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBProjectSource</string> + <string key="minorKey">browser/cocoa/nsmenuitem_additions.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> <string key="className">NSObject</string> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBProjectSource</string> @@ -1233,7 +1225,7 @@ <string key="superclassName">NSViewController</string> <object class="NSMutableDictionary" key="actions"> <bool key="EncodedWithXMLCoder">YES</bool> - <object class="NSMutableArray" key="dict.sortedKeys"> + <object class="NSArray" key="dict.sortedKeys"> <bool key="EncodedWithXMLCoder">YES</bool> <string>closeTab:</string> <string>commandDispatch:</string> @@ -1246,7 +1238,7 @@ </object> <object class="NSMutableDictionary" key="outlets"> <bool key="EncodedWithXMLCoder">YES</bool> - <object class="NSMutableArray" key="dict.sortedKeys"> + <object class="NSArray" key="dict.sortedKeys"> <bool key="EncodedWithXMLCoder">YES</bool> <string>closeButton_</string> <string>contextMenu_</string> @@ -1269,8 +1261,483 @@ </object> </object> </object> + <object class="NSMutableArray" key="referencedPartialClassDescriptionsV3.2+"> + <bool key="EncodedWithXMLCoder">YES</bool> + <object class="IBPartialClassDescription"> + <string key="className">NSActionCell</string> + <string key="superclassName">NSCell</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSActionCell.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSApplication</string> + <string key="superclassName">NSResponder</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier" id="534124792"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSApplication.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSApplication</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier" id="110289917"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSApplicationScripting.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSApplication</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier" id="1071879904"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSColorPanel.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSApplication</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSHelpManager.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSApplication</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSPageLayout.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSApplication</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSUserInterfaceItemSearching.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSButton</string> + <string key="superclassName">NSControl</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSButton.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSButtonCell</string> + <string key="superclassName">NSActionCell</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSButtonCell.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSCell</string> + <string key="superclassName">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSCell.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSControl</string> + <string key="superclassName">NSView</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier" id="1072052318"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSControl.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSFormatter</string> + <string key="superclassName">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">Foundation.framework/Headers/NSFormatter.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSMenu</string> + <string key="superclassName">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier" id="215012535"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSMenu.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSMenuItem</string> + <string key="superclassName">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier" id="858214781"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSMenuItem.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSAccessibility.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <reference key="sourceIdentifier" ref="534124792"/> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <reference key="sourceIdentifier" ref="110289917"/> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <reference key="sourceIdentifier" ref="1071879904"/> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <reference key="sourceIdentifier" ref="1072052318"/> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSDictionaryController.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSDragging.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSFontManager.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSFontPanel.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSKeyValueBinding.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <reference key="sourceIdentifier" ref="215012535"/> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSNibLoading.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSOutlineView.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSPasteboard.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSSavePanel.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSTableView.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSToolbarItem.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier" id="246401013"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSView.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">Foundation.framework/Headers/NSArchiver.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">Foundation.framework/Headers/NSClassDescription.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">Foundation.framework/Headers/NSError.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">Foundation.framework/Headers/NSFileManager.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">Foundation.framework/Headers/NSKeyValueCoding.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">Foundation.framework/Headers/NSKeyValueObserving.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">Foundation.framework/Headers/NSKeyedArchiver.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">Foundation.framework/Headers/NSObject.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">Foundation.framework/Headers/NSObjectScripting.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">Foundation.framework/Headers/NSPortCoder.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">Foundation.framework/Headers/NSRunLoop.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">Foundation.framework/Headers/NSScriptClassDescription.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">Foundation.framework/Headers/NSScriptKeyValueCoding.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">Foundation.framework/Headers/NSScriptObjectSpecifiers.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">Foundation.framework/Headers/NSScriptWhoseTests.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">Foundation.framework/Headers/NSThread.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">Foundation.framework/Headers/NSURL.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">Foundation.framework/Headers/NSURLConnection.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">Foundation.framework/Headers/NSURLDownload.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">QuartzCore.framework/Headers/CAAnimation.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">QuartzCore.framework/Headers/CALayer.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">QuartzCore.framework/Headers/CIImageProvider.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">SecurityInterface.framework/Headers/SFAuthorizationView.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">SecurityInterface.framework/Headers/SFCertificatePanel.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">SecurityInterface.framework/Headers/SFChooseIdentityPanel.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSResponder</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSInterfaceStyle.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSResponder</string> + <string key="superclassName">NSObject</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSResponder.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSTextField</string> + <string key="superclassName">NSControl</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSTextField.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSTextFieldCell</string> + <string key="superclassName">NSActionCell</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSTextFieldCell.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSView</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSClipView.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSView</string> + <reference key="sourceIdentifier" ref="858214781"/> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSView</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSRulerView.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSView</string> + <string key="superclassName">NSResponder</string> + <reference key="sourceIdentifier" ref="246401013"/> + </object> + <object class="IBPartialClassDescription"> + <string key="className">NSViewController</string> + <string key="superclassName">NSResponder</string> + <object class="NSMutableDictionary" key="outlets"> + <string key="NS.key.0">view</string> + <string key="NS.object.0">NSView</string> + </object> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBFrameworkSource</string> + <string key="minorKey">AppKit.framework/Headers/NSViewController.h</string> + </object> + </object> + </object> </object> <int key="IBDocument.localizationMode">0</int> + <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencies"> + <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.macosx</string> + <integer value="1050" key="NS.object.0"/> + </object> + <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencyDefaults"> + <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.macosx</string> + <integer value="1050" key="NS.object.0"/> + </object> + <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies"> + <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3</string> + <integer value="3000" key="NS.object.0"/> + </object> + <bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool> <string key="IBDocument.LastKnownRelativeProjectPath">../../chrome.xcodeproj</string> <int key="IBDocument.defaultPropertyAccessControl">3</int> </data> diff --git a/chrome/browser/cocoa/bookmark_bar_constants.h b/chrome/browser/cocoa/bookmark_bar_constants.h index ba1b576..216fc8c 100644 --- a/chrome/browser/cocoa/bookmark_bar_constants.h +++ b/chrome/browser/cocoa/bookmark_bar_constants.h @@ -22,6 +22,9 @@ const int kNTPBookmarkBarHeight = 40; const int kNTPBookmarkBarPadding = (kNTPBookmarkBarHeight - kBookmarkBarHeight) / 2; +// The height of buttons in the bookmark bar. +const int kBookmarkButtonHeight = kBookmarkBarHeight; + } // namespace bookmarks #endif // CHROME_BROWSER_COCOA_BOOKMARK_BAR_CONSTANTS_H_ diff --git a/chrome/browser/cocoa/bookmark_bar_controller.h b/chrome/browser/cocoa/bookmark_bar_controller.h index e01312f..dbf8e7c 100644 --- a/chrome/browser/cocoa/bookmark_bar_controller.h +++ b/chrome/browser/cocoa/bookmark_bar_controller.h @@ -95,8 +95,11 @@ const CGFloat kNoBookmarksNTPVerticalOffset = 27.0; scoped_ptr<TabStripModelObserverBridge> tabObserver_; IBOutlet BookmarkBarView* buttonView_; - IBOutlet MenuButton* offTheSideButton_; + IBOutlet MenuButton* offTheSideButton_; // aka the chevron IBOutlet NSMenu* buttonContextMenu_; + + // "Other bookmarks" button on the right side. + scoped_nsobject<NSButton> otherBookmarksButton_; } // Initializes the bookmark bar controller with the given browser @@ -184,6 +187,7 @@ const CGFloat kNoBookmarksNTPVerticalOffset = 27.0; @interface BookmarkBarController(InternalOrTestingAPI) // Set the delegate for a unit test. - (void)setUrlDelegate:(id<BookmarkURLOpener>)urlDelegate; +- (NSCell*)cellForBookmarkNode:(const BookmarkNode*)node; - (void)clearBookmarkBar; - (BookmarkBarView*)buttonView; - (NSArray*)buttons; @@ -196,6 +200,8 @@ const CGFloat kNoBookmarksNTPVerticalOffset = 27.0; - (int32)menuTagFromNodeId:(int64)menuid; - (void)buildOffTheSideMenu; - (NSMenu*)offTheSideMenu; +- (NSButton*)offTheSideButton; +- (NSButton*)otherBookmarksButton; @end #endif // CHROME_BROWSER_COCOA_BOOKMARK_BAR_CONTROLLER_H_ diff --git a/chrome/browser/cocoa/bookmark_bar_controller.mm b/chrome/browser/cocoa/bookmark_bar_controller.mm index 2ee2e53..bdbe4ad 100644 --- a/chrome/browser/cocoa/bookmark_bar_controller.mm +++ b/chrome/browser/cocoa/bookmark_bar_controller.mm @@ -52,6 +52,10 @@ - (void)tagEmptyMenu:(NSMenu*)menu; - (void)clearMenuTagMap; - (int)preferredHeight; +- (void)addNonBookmarkButtonsToView; +- (void)addButtonsToView; +- (void)resizeButtons; +- (void)centerNoItemsLabel; @end @implementation BookmarkBarController @@ -105,16 +109,21 @@ // done. Thus, this call is (almost) last. bridge_.reset(new BookmarkBarBridge(self, bookmarkModel_)); + DCHECK([offTheSideButton_ attachedMenu]); + + // To make life happier when the bookmark bar is floating, the + // chevron is a child of the button view. + [offTheSideButton_ removeFromSuperview]; + [buttonView_ addSubview:offTheSideButton_]; + // When resized we may need to add new buttons, or remove them (if // no longer visible), or add/remove the "off the side" menu. [[self view] setPostsFrameChangedNotifications:YES]; [[NSNotificationCenter defaultCenter] - addObserver:self - selector:@selector(frameDidChange) - name:NSViewFrameDidChangeNotification - object:[self view]]; - - DCHECK([offTheSideButton_ attachedMenu]); + addObserver:self + selector:@selector(frameDidChange) + name:NSViewFrameDidChangeNotification + object:[self view]]; } // Method is the same as [self view], but is provided to be explicit. @@ -127,18 +136,28 @@ [self showBookmarkBar:YES immediately:YES]; } -// Check if we should enable the off-the-side button. +// Position the off-the-side chevron to the left of the otherBookmarks button. +- (void)positionOffTheSideButton { + NSRect frame = [offTheSideButton_ frame]; + frame.origin.x = ([otherBookmarksButton_ frame].origin.x - + (frame.size.width + bookmarks::kBookmarkHorizontalPadding)); + [offTheSideButton_ setFrame:frame]; +} + +// Check if we should enable or disable the off-the-side chevron. +// Assumes that buttons which don't fit in the parent view are removed +// from it. +// // TODO(jrg): when we are smarter about creating buttons (e.g. don't // bother creating buttons which aren't visible), we'll have to be // smarter here too. -- (void)checkHideOffTheSideButton { +- (void)showOrHideOffTheSideButton { + // Then determine if we'll hide or show it. NSButton* button = [buttons_ lastObject]; - if ((!button) || - (NSMaxX([button frame]) <= - NSMaxX([[button superview] frame]))) { - [offTheSideButton_ setHidden:YES]; - } else { + if (button && ![button superview]) { [offTheSideButton_ setHidden:NO]; + } else { + [offTheSideButton_ setHidden:YES]; } } @@ -147,11 +166,16 @@ } // Called when our controlled frame has changed size. -// TODO(jrg): be smarter (e.g. add/remove buttons as appropriate). - (void)frameDidChange { - [self checkHideOffTheSideButton]; + [self resizeButtons]; + [self positionOffTheSideButton]; + [self addButtonsToView]; + [self showOrHideOffTheSideButton]; + [self centerNoItemsLabel]; +} - // Need to keep the "no items" label centered. +// Keep the "no items" label centered in response to a frame size change. +- (void)centerNoItemsLabel { NSView* noItemsView = [buttonView_ noItemTextfield]; NSRect frame = [noItemsView frame]; NSRect parent = [buttonView_ bounds]; @@ -163,6 +187,28 @@ [noItemsView setFrameOrigin:newOrigin]; } +// Change the layout of the bookmark bar's subviews in response to a +// visibility change (e.g. show or hide the bar) or style change +// (attached or floating). +- (void)layoutSubviews { + if ([self drawAsFloatingBar]) { + // The internal bookmark bar should have padding to center it. + NSRect frame = [[self view] frame]; + [buttonView_ setFrame: + NSMakeRect(bookmarks::kNTPBookmarkBarPadding, + bookmarks::kNTPBookmarkBarPadding, + (NSWidth(frame) - + bookmarks::kNTPBookmarkBarPadding*2), + (NSHeight(frame) - + bookmarks::kNTPBookmarkBarPadding))]; + } else { + // The frame of our child should be equal to our frame, excluding + // space for stuff on the right side (e.g. off-the-side chevron). + NSRect frame = [[self view] frame]; + [buttonView_ setFrame:NSMakeRect(0, 0, NSWidth(frame), NSHeight(frame))]; + } +} + // Show or hide the bar based on the value of |show|. Handles animating the // resize of the content view. if |immediately| is YES, make changes // immediately instead of using an animator. The routine which enables the bar @@ -177,7 +223,8 @@ [[self view] setHidden:show ? NO : YES]; DCHECK([[self view] isKindOfClass:[BookmarkBarToolbarView class]]); - [(BookmarkBarToolbarView*)[self view] layoutViews]; + [self layoutSubviews]; + [self frameDidChange]; } // We don't change a preference; we only change visibility. @@ -394,13 +441,10 @@ for (NSInteger i = [menu numberOfItems] - 1; i >= 1 ; i--) [menu removeItemAtIndex:i]; - // Add items corresponding to buttons which aren't displayed or are only - // partly displayed. - for (NSButton* each_button in buttons_.get()) { - if (NSMaxX([each_button frame]) > - NSMaxX([[each_button superview] frame])) { - [self addNode:[self nodeFromButton:each_button] toMenu:menu]; - } + // Add items corresponding to buttons which aren't displayed. + for (NSButton* button in buttons_.get()) { + if (![button superview]) + [self addNode:[self nodeFromButton:button] toMenu:menu]; } } @@ -532,8 +576,8 @@ return buttonView_; } -// Delete all bookmarks from the bookmark bar, and reset knowledge of -// bookmarks. +// Delete all buttons (bookmarks, chevron, "other bookmarks") from the +// bookmark bar; reset knowledge of bookmarks. - (void)clearBookmarkBar { [buttons_ makeObjectsPerformSelector:@selector(removeFromSuperview)]; [buttons_ removeAllObjects]; @@ -589,7 +633,7 @@ // the height wasn't precisely zero. The previous author wrote that they were // doing this because of an animator, but we are not doing animations for beta // so we do not care. - bounds.size.height = bookmarks::kBookmarkBarHeight; + bounds.size.height = bookmarks::kBookmarkButtonHeight; NSRect frame = NSInsetRect(bounds, bookmarks::kBookmarkHorizontalPadding, @@ -615,17 +659,17 @@ if (delta) { frame.size.width = desiredSize; [button setFrame:frame]; - for (NSButton* each_button in buttons_.get()) { - NSRect each_frame = [each_button frame]; - if (each_frame.origin.x > frame.origin.x) { - each_frame.origin.x += delta; - [each_button setFrame:each_frame]; + for (NSButton* button in buttons_.get()) { + NSRect buttonFrame = [button frame]; + if (buttonFrame.origin.x > frame.origin.x) { + buttonFrame.origin.x += delta; + [button setFrame:buttonFrame]; } } } // We may have just crossed a threshold to enable the off-the-side // button. - [self checkHideOffTheSideButton]; + [self showOrHideOffTheSideButton]; } - (IBAction)openBookmarkMenuItem:(id)sender { @@ -636,22 +680,22 @@ [urlDelegate_ openBookmarkURL:node->GetURL() disposition:disposition]; } -// Add all items from the given model to our bookmark bar. +// Create buttons for all items in the bookmark node tree. // // TODO(jrg): write a "build bar" so there is a nice spot for things // like the contextual menu which is invoked when not over a // bookmark. On Safari that menu has a "new folder" option. -- (void)addNodesToBar:(const BookmarkNode*)node { +- (void)addNodesToButtonList:(const BookmarkNode*)node { BOOL hidden = (node->GetChildCount() == 0) ? NO : YES; NSView* item = [buttonView_ noItemTextfield]; [item setHidden:hidden]; - int x_offset = 0; + int xOffset = 0; for (int i = 0; i < node->GetChildCount(); i++) { const BookmarkNode* child = node->GetChild(i); NSCell* cell = [self cellForBookmarkNode:child]; - NSRect frame = [self frameForBookmarkButtonFromCell:cell xOffset:&x_offset]; + NSRect frame = [self frameForBookmarkButtonFromCell:cell xOffset:&xOffset]; NSButton* button = [[[BookmarkButton alloc] initWithFrame:frame] autorelease]; DCHECK(button); @@ -678,11 +722,96 @@ url_string.c_str()]; [button setToolTip:tooltip]; } - // Finally, add it to the bookmark bar. - [buttonView_ addSubview:button]; } } +// Add non-bookmark buttons to the view. This includes the chevron +// and the "other bookmarks" button. Technically "other bookmarks" is +// a bookmark button but it is treated specially. Only needs to be +// called when these buttons are new or when the bookmark bar is +// cleared (e.g. on a loaded: call). Unlike addButtonsToView below, +// we don't need to add/remove these dynamically in response to window +// resize. +- (void)addNonBookmarkButtonsToView { + [buttonView_ addSubview:otherBookmarksButton_.get()]; + [buttonView_ addSubview:offTheSideButton_]; +} + +// Add bookmark buttons to the view only if they are completely +// visible and don't overlap the "other bookmarks". Remove buttons +// which are clipped. Called when building the bookmark bar and when +// the window resizes. +- (void)addButtonsToView { + NSView* superview = nil; + for (NSButton* button in buttons_.get()) { + superview = [button superview]; + if (NSMaxX([button frame]) <= NSMinX([offTheSideButton_ frame])) { + if (!superview) + [buttonView_ addSubview:button]; + } else { + if (superview) + [button removeFromSuperview]; + } + } +} + +// Helper for resizeButtons to resize buttons based on a new parent +// view height. +- (void)resizeButtonsInArray:(NSArray*)array { + NSRect parentBounds = [buttonView_ bounds]; + CGFloat height = (bookmarks::kBookmarkButtonHeight - + (bookmarks::kBookmarkVerticalPadding*2)); + for (NSButton* button in array) { + NSRect frame = [button frame]; + frame.size.height = height; + [button setFrame:frame]; + } +} + +// Resize our buttons; the parent view height may have changed. This +// applies to all bookmarks, the chevron, and the "Other Bookmarks" +- (void)resizeButtons { + [self resizeButtonsInArray:buttons_.get()]; + NSMutableArray* array = [NSMutableArray arrayWithObject:offTheSideButton_]; + // We must handle resize before the bookmarks are loaded. If not loaded, + // we have no otherBookmarksButton_ yet. + if (otherBookmarksButton_.get()) + [array addObject:otherBookmarksButton_.get()]; + [self resizeButtonsInArray:array]; +} + +// Create the button for "Other Bookmarks" on the right of the bar. +- (void)createOtherBookmarksButton { + // Can't create this until the model is loaded, but only need to + // create it once. + if (otherBookmarksButton_.get()) + return; + + // TODO(jrg): remove duplicate code + NSCell* cell = [self cellForBookmarkNode:bookmarkModel_->other_node()]; + int ignored = 0; + NSRect frame = [self frameForBookmarkButtonFromCell:cell xOffset:&ignored]; + frame.origin.x = [[self buttonView] bounds].size.width - frame.size.width; + frame.origin.x -= bookmarks::kBookmarkHorizontalPadding; + NSButton* button = [[BookmarkButton alloc] initWithFrame:frame]; + otherBookmarksButton_.reset(button); + + // Peg at right; keep same height as bar. + [button setAutoresizingMask:(NSViewMinXMargin)]; + [button setCell:cell]; + [button setTarget:self]; + [button setAction:@selector(openFolderMenuFromButton:)]; + [buttonView_ addSubview:button]; + + // Now that it's here, move the chevron over. + NSRect oframe = [offTheSideButton_ frame]; + oframe.origin.x = frame.origin.x - (oframe.size.width + + bookmarks::kBookmarkHorizontalPadding); + + // Force it to be the right size, right now. + [self resizeButtons]; +} + // TODO(jrg): for now this is brute force. - (void)loaded:(BookmarkModel*)model { DCHECK(model == bookmarkModel_); @@ -691,8 +820,13 @@ // Else brute force nuke and build. const BookmarkNode* node = model->GetBookmarkBarNode(); [self clearBookmarkBar]; - [self addNodesToBar:node]; - [self checkHideOffTheSideButton]; + [self addNodesToButtonList:node]; + [self createOtherBookmarksButton]; + [self resizeButtons]; + [self positionOffTheSideButton]; + [self addNonBookmarkButtonsToView]; + [self addButtonsToView]; + [self showOrHideOffTheSideButton]; } - (void)beingDeleted:(BookmarkModel*)model { @@ -767,4 +901,12 @@ return buttons_.get(); } +- (NSButton*)offTheSideButton { + return offTheSideButton_; +} + +- (NSButton*)otherBookmarksButton { + return otherBookmarksButton_.get(); +} + @end diff --git a/chrome/browser/cocoa/bookmark_bar_controller_unittest.mm b/chrome/browser/cocoa/bookmark_bar_controller_unittest.mm index a777e8c..5f645bf 100644 --- a/chrome/browser/cocoa/bookmark_bar_controller_unittest.mm +++ b/chrome/browser/cocoa/bookmark_bar_controller_unittest.mm @@ -218,7 +218,7 @@ TEST_F(BookmarkBarControllerTest, ShowOnNewTabPage) { bar.reset( [[AlwaysNewTabPageBookmarkBarController alloc] initWithBrowser:helper_.browser() - initialWidth:100 // arbitrary + initialWidth:800 // arbitrary compressDelegate:compressDelegate_.get() resizeDelegate:resizeDelegate_.get() urlDelegate:nil]); @@ -231,6 +231,32 @@ TEST_F(BookmarkBarControllerTest, ShowOnNewTabPage) { EXPECT_FALSE([[bar view] isHidden]); EXPECT_GT([resizeDelegate_ height], 0); EXPECT_GT([[bar view] frame].size.height, 0); + + // Make sure no buttons fall off the bar, either now or when resized + // bigger or smaller. + CGFloat sizes[] = { 300.0, -100.0, 200.0, -420.0 }; + CGFloat previousX = 0.0; + for (unsigned x = 0; x < arraysize(sizes); x++) { + // Confirm the buttons moved from the last check (which may be + // init but that's fine). + CGFloat newX = [[bar offTheSideButton] frame].origin.x; + EXPECT_NE(previousX, newX); + previousX = newX; + + // Confirm the buttons have a reasonable bounds. + EXPECT_TRUE(NSContainsRect([[bar buttonView] frame], + [[bar offTheSideButton] frame])); + EXPECT_TRUE(NSContainsRect([[bar buttonView] frame], + [[bar otherBookmarksButton] frame])); + + // Now move them implicitly. + // We confirm FrameChangeNotification works in the next unit test; + // we simply assume it works here to resize or reposition the + // buttons above. + NSRect frame = [[bar view] frame]; + frame.size.width += sizes[x]; + [[bar view] setFrame:frame]; + } } // Make sure we're watching for frame change notifications. @@ -552,18 +578,22 @@ TEST_F(BookmarkBarControllerTest, OpenAllBookmarks) { // TODO(jrg): write a test to confirm that nodeFavIconLoaded calls // checkForBookmarkButtonGrowth:. -// TODO(jrg): Make sure showing the bookmark bar calls loaded: (to -// process bookmarks) -TEST_F(BookmarkBarControllerTest, ShowAndLoad) { -} - -// TODO(jrg): Test cellForBookmarkNode: TEST_F(BookmarkBarControllerTest, Cell) { -} + BookmarkModel* model = helper_.profile()->GetBookmarkModel(); + [bar_ loaded:model]; -TEST_F(BookmarkBarControllerTest, Contents) { - // TODO(jrg): addNodesToBar has a LOT of TODOs; when flushed out, write - // appropriate tests. + const BookmarkNode* parent = model->GetBookmarkBarNode(); + model->AddURL(parent, parent->GetChildCount(), + L"supertitle", + GURL("http://superfriends.hall-of-justice.edu")); + const BookmarkNode* node = parent->GetChild(0); + + NSCell* cell = [bar_ cellForBookmarkNode:node]; + EXPECT_TRUE(cell); + EXPECT_TRUE([[cell title] isEqual:@"supertitle"]); + EXPECT_EQ(node, [[cell representedObject] pointerValue]); + + // cell is autoreleased; no need to release here } // Test drawing, mostly to ensure nothing leaks or crashes. @@ -700,10 +730,4 @@ TEST_F(BookmarkBarControllerTest, DropBookmarks) { } } - -// Cannot test these methods since they simply call a single static -// method, BookmarkEditor::Show(), which is impossible to mock. -// editBookmark:, addPage: - - } // namespace diff --git a/chrome/browser/cocoa/bookmark_bar_toolbar_view.h b/chrome/browser/cocoa/bookmark_bar_toolbar_view.h index cfc9288..0eb79ca 100644 --- a/chrome/browser/cocoa/bookmark_bar_toolbar_view.h +++ b/chrome/browser/cocoa/bookmark_bar_toolbar_view.h @@ -33,6 +33,7 @@ class ThemeProvider; // Returns true if the bookmark bar should be drawn as if it's a disconnected // bookmark bar on the New Tag Page. - (BOOL)drawAsFloatingBar; + @end @interface BookmarkBarToolbarView : BackgroundGradientView { @@ -40,15 +41,7 @@ class ThemeProvider; // The controller which tells us how we should be drawing (as normal or as a // floating bar). IBOutlet id<BookmarkBarToolbarViewController> controller_; - - // The bookmark bar's contents. - IBOutlet BookmarkBarView* buttonView_; } - -// Called by our controller to layout our subviews, so that on new tab pages, -// we have a border. -- (void)layoutViews; - @end #endif // CHROME_BROWSER_COCOA_BOOKMARK_BAR_TOOLBAR_VIEW_H_ diff --git a/chrome/browser/cocoa/bookmark_bar_toolbar_view.mm b/chrome/browser/cocoa/bookmark_bar_toolbar_view.mm index 05acccc..119192e 100644 --- a/chrome/browser/cocoa/bookmark_bar_toolbar_view.mm +++ b/chrome/browser/cocoa/bookmark_bar_toolbar_view.mm @@ -36,24 +36,6 @@ const CGFloat kBorderRadius = 3.0; } } -- (void)layoutViews { - if ([controller_ drawAsFloatingBar]) { - // The internal bookmark bar should have padding to center it. - NSRect frame = [self frame]; - [buttonView_ setFrame: - NSMakeRect(bookmarks::kNTPBookmarkBarPadding, - bookmarks::kNTPBookmarkBarPadding, - NSWidth(frame) - - bookmarks::kNTPBookmarkBarPadding, - NSHeight(frame) - - bookmarks::kNTPBookmarkBarPadding)]; - } else { - // The frame of our child should be equal to our frame. - NSRect frame = [self frame]; - [buttonView_ setFrame:NSMakeRect(0, 0, NSWidth(frame), NSHeight(frame))]; - } -} - - (void)drawRectAsFloating:(NSRect)rect { NSRect bounds = [self bounds]; |